c++链表小问题,麻烦帮帮忙。。

[复制链接]
查看11 | 回复1 | 2009-4-15 21:08:58 | 显示全部楼层 |阅读模式
这程序是建立链表
但是为什么只能输入一次数据??
#include "stdafx.h"
#include
#include "malloc.h"
#define LEN sizeof (struct student)
using namespace std;
struct student
{
long num;
float score;
struct student *next;
};
struct student *creat(void)
{
int n=0;
struct student *p1,*p2,*head;
p1=(struct student*)malloc (LEN);
cin>>p1->num>>p1->score;
head=NULL;
while(p1->num!=0)
{
if(n==0)
{head=p1;p2=p1;}
else
{
p2->next=p1;
p2=p1;
p1=(struct student*)malloc (LEN);
cin>>p1->num>>p1->score;
n=n+1;
}
}
p2->next=NULL;
return(head);
}

回复

使用道具 举报

千问 | 2009-4-15 21:08:58 | 显示全部楼层
#include "stdafx.h" #include #include "malloc.h" #define LEN sizeof (struct student) using namespace std; struct student { long num; float score; struct student *next; }; struct student *creat(void) { int n=0; struct student *p1,*p2,*head; p1=(struct student*)malloc(LEN); cin>>p1->n...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行