,排序有关问题?

求助,排序问题????
不知道为什么不能正常的排序,不知道哪里出错了,好郁闷,求路过的帮帮我,多谢,多谢!!
[code=C/C++][/code]#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int j=1;

struct PhoneMessage //数据类
{
char name[10]; //姓名
char lPhoneNumber[15]; //长号
char sPhoneNumber[10]; //短号
string idNumber; //身份证号
string email; //邮箱地址
PhoneMessage *next;
int s;

void Input(); //输入信息
void Display(); //输出信息
};

class PhoneFunction //功能类
{
public:
PhoneFunction(); //构造函数
void Insert(); //插入信息
void Show(); //显示全部人的电话信息
void Exchange(PhoneMessage *,PhoneMessage *); //两个对象交换数据域
void Sort(); //按长号大小排序
private:
PhoneMessage *head,*rear;
ifstream infile;
ofstream outfile;
};


PhoneFunction::PhoneFunction()
{
head=new PhoneMessage; //生成头结点
head->next=new PhoneMessage;
rear=head->next;
}

void PhoneMessage::Input()
{
cout<<"请输入姓名:";
cin>>name;
cout<<"请输入电话号码(长号):";
cin>>lPhoneNumber;
cout<<"请输入电话号码(短号):";
cin>>sPhoneNumber;
cout<<"请输入身份证号码:";
cin>>idNumber;
cout<<"请输入邮箱地址:";
cin>>email;
s=j++;
}

void PhoneMessage::Display()
{
cout<<"姓名:"<<name<<'\t'<<"长号:"<<lPhoneNumber<<'\t'
<<"短号:"<<sPhoneNumber<<'\t'<<"身份证号码:"<<idNumber
<<'\t'<<"电子邮箱地址:"<<email<<endl;
}


void PhoneFunction::Insert() //尾插法插入数据
{
char c='y';
while(c=='y')  
{
rear->Input();
rear->next=new PhoneMessage;
rear=rear->next;
cout<<"是否继续输入(y/n)......";
cin>>c;
}

}

void PhoneFunction::Sort() //冒泡排序
{
PhoneMessage *p;
int k;
for(int i=0;i<j-1;i++)
{
p=head->next;
for(k=0;k<(j-1-i);k++)
{
if(strcmp(p->lPhoneNumber,p->next->lPhoneNumber)>0)
Exchange(p,p->next);
p=p->next;
}
}
cout<<endl;
cout<<"按长号的大小排序,结果为:"<<endl;
Show();
}


void PhoneFunction::Exchange(PhoneMessage *p1,PhoneMessage *p2) //交换两个对象的数据域
{
PhoneMessage *temp;
strcpy(temp->name,p1->name);
strcpy(temp->lPhoneNumber,p1->lPhoneNumber);
strcpy(temp->sPhoneNumber,p1->sPhoneNumber);
temp->idNumber=p1->idNumber;
temp->email=p1->email;
temp->s=p1->s;

strcpy(p1->name,p2->name);
strcpy(p1->lPhoneNumber,p2->lPhoneNumber);
strcpy(p1->sPhoneNumber,p2->sPhoneNumber);
p1->idNumber=p2->idNumber;
p1->email=p2->email;
p1->s=p2->s;

strcpy(p2->name,temp->name);
strcpy(p2->lPhoneNumber,temp->lPhoneNumber);
strcpy(p2->sPhoneNumber,temp->sPhoneNumber);
p2->idNumber=temp->idNumber;
p2->email=temp->email;
p2->s=temp->s;
}


void PhoneFunction::Show() //显示全部信息
{
for(PhoneMessage *p=head->next;p!=rear;p=p->next)
p->Display();
cout<<endl;
}

int main()
{
PhoneFunction Ph;
Ph.Insert();
Ph.Sort();
Ph.Show();
return 0;
}


------解决方案--------------------
建立链表的时候没有把最后的指针设置为NULL吧??
当你要把数据拷贝进指针所指的内存空间内的时候要先确保你指针已经指向了内存啊。你的Exchange函数就犯了这个错误。