该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
int iCount=0;
struct student
{
char cName[7];
int iNumber;
struct student *pNext;
};
struct student* Create()
{
struct student *pHead,*pNew,*pEnd;
pNew=pEnd=(struct student*)malloc(sizeof(struct student*));
pHead=NULL;
printf("请分别输入姓名、账号,用空格键隔开,输入0退出\n");
scanf("%s",&pNew->cName);
scanf("%d",&pNew->iNumber);
while(pNew->iNumber!=0)
{
iCount++;
if(iCount==1)
{
pNew->pNext=pHead;
pHead=pNew;
pHead=pEnd;
}
else
{
pNew->pNext=NULL;
pEnd->pNext=pNew;
pEnd=pNew;
}
pNew=(struct student*)malloc(sizeof(struct student*));
scanf("%s",&pNew->cName);
scanf("%d",&pNew->iNumber);
}
return pHead;
}
void Print(struct student* pHead)
{
struct student *pTemp;
pTemp=pHead;
while(pTemp!=NULL)
{
printf("%s\t",pTemp->cName);
printf("%d\n",pTemp->iNumber);
pTemp=pTemp->pNext;
}
}
struct student* Insert(struct student* pHead)
{
struct student *pNew,*pEnd;
pNew=pEnd=(struct student*)malloc(sizeof(struct student*));
printf("请分别输入要插入的姓名、账号,用空格键隔开\n");
scanf("%s",&pNew->cName);
scanf("%d",&pNew->iNumber);
pNew->pNext=NULL;
pEnd->pNext=pNew;
pEnd=pNew;
iCount++;
Print(pHead);
return pHead;
};
部分代码如上,头插入可以完成,尾插入就插入不成功。插入了,没输出新插入的,只输出已有的。