我的程序能通过编译,不过途中提示遇到错误,强制关闭。
望各位大虾帮帮忙,指点迷津!
#include<iostream.h>
struct part
{
long num;
part *next;
};
part *head;
part *original()
{
cout<<"请输入原链表的号码:"<<endl;
part *ps;
ps=new part;
cin>>ps->num;
part *end;
end=ps;
head=ps;
for(int i=0;i<3;i++)
{
ps=new part;
cin>>ps->num;
end->next=ps;
end=ps;
}
end->next=NULL;
delete ps;
return (head);
} //原链表的函数
void oppsite(part *dest) //逆置表的函数
{
cout<<"head-->";
while(dest)
{
cout<<dest->num<<"-->";
dest =dest->next;
}
cout<<"NULL"<<endl; //先打印原链表,dest的值回到空值
part *head1; //新建逆置链表的链首head1
head1=dest;
part *ps1;
ps1=dest;
ps1->next=dest-8; //一个dest的大小为8,从空值返回到上一个值(这里不太肯定,不知道对不对)
while(dest)
{
ps1=dest;
dest=dest-8;
ps1->next=dest-8;
}
ps1->next=NULL; //制逆置表完毕
cout<<"head-->";
while(head1)
{
cout<<head1->num<<"-->";
head1=head1->next;
}
cout<<"NULL"<<endl;
} //打印逆置链表
void main()
{
oppsite(original());
}