高手进来看一下这个程序吧!

来源:百度知道 编辑:UC知道 时间:2024/05/23 11:50:25
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "process.h"
struct STOCK2
{
long stockcode;
char stockname[20];
struct STOCK2 *next;
};
struct STOCK2 *insert_end(struct STOCK2 *head)//在链表的尾部插入一个新的结点,返回头措针
{
struct STOCK2 *p,*q;
p=(struct STOCK2 *)malloc(sizeof(struct STOCK2));//申请一个新结点用p指向该结点
if(p==NULL) exit(1);
puts("Please input stockname and stockcode");
scanf("%s%ld",p->stockname,&p->stockcode);
p->next=NULL;

if(head=NULL)
return p;
else
{
q=head;
while(q->next!=NULL) //走链到最后一个结点
q=q->next; //最后一个结点指向新插入的结点
q->next=p;
return head;
}
}
void show(struct STOCK2 *head)
{
struct STOCK2 *p;
p=head;
while(p!=NULL)
{
printf("\n%20s %06ld",p->stockname,p->

1.
insert_end()函数中的

if(head=NULL)
改为
if(head==NULL)

2.
show()函数中
while(p!=NULL)
{
printf("\n%20s %06ld",p->stockname,p->stockcode);
p->next;
}
改为
while(p!=NULL)
{
printf("\n%20s %06ld",p->stockname,p->stockcode);
p=p->next;/*注意这里*/
}

****************************************************

修改后的完整程序:

//---------------------------------------------------------------------------

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "process.h"
struct STOCK2
{
long stockcode;
char stockname[20];
struct STOCK2 *next;
};
struct STOCK2 *insert_end(struct STOCK2 *head)//在链表的尾部插入一个新的结点,返回头措针
{
struct STOCK2 *p,*q;
p=(struct STOCK2 *)malloc(sizeof(struct STOCK2));//申请一个新结点用p指向该结点
if(p==NUL