vc++程序查错

来源:百度知道 编辑:UC知道 时间:2024/05/31 01:28:55
#include <iostream.h>
struct node
{
char data;
node* next;
};
node* create();
void addnode(node* head,char keyword);
void showlist(node* head);
void deletenode(node* head,char keyword);

void main()
{
node* temp=create();
showlist(temp);
char key;
cin>>key;
addnode(temp,key);
cin>>key;
deletenode(temp,key);
}

node* create()
{
node* phead=NULL;
node* pend=phead;
node* ps=NULL;
char temp;
do
{
cin>>temp;
if (temp!='#')
{
ps=new node;
ps->data=temp;
ps->next=NULL;
if (phead==NULL)
{
phead=ps;
}
else
{
pend->next=ps;
}
pend=ps;
}
}while(temp!='#');
return phead;
}
void showlist(node* head)
{
node* ps=head;
while(ps!=N

while(ps!=NULL)
{
if (ps->data=keyword)
{
break;
}
else
{
ps=ps->next;
}
其中if的条件判断出了问题!!
还有你在删除了一个结点后 并没有释放之前申请的空间

这个程序没错啊,在VC++6.0中运行好着呢