数据结构代码修改

来源:百度知道 编辑:UC知道 时间:2024/09/14 09:43:16
编写程序创建一个保存学生基本信息的单链表,实现学生信息的建立(尾部插入和头部插入都要) 插入 删除 查看 逆置 删除值为X 等功能
下面是我写的代码,有插入,删除,查找,删除i结点,但是错误该不出来。这儿先谢谢了
#define NULL 0
#define LIST_size 100
#define LISTINCREMENT 10
#define OVERFLOW -2
#define ERROR 0
#define OK 1
#define FALSE 0
#define TURE 1

struct student{
char name[20];
int age;
struct student *next;
};
int n=0;

struct student *initlist_sq1(void){
struct student *p1,*p2,*head;
char c;
p1=p2=(struct student *)malloc(sizeof( struct student));
if(! p1)
exit (OVERFLOW);
gets(&p1->name);
scanf("%d",&p1->age);
head=NULL;
while(p1->name!=NULL){
n++;
if( n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(sizeof( struct student));
gets(&p1->name);
scanf("%d",p1->age);
printf("Once again y/n");
sca

太多错了,,不过现在可以编译通过了
#include<stdio.h>
#include<stdlib.h>
//#define NULL 0
#define LIST_size 100
#define LISTINCREMENT 10
#define OVERFLOW -2
#define ERROR 0
#define OK 1
#define FALSE 0
#define TURE 1

struct student{
char name[20];
int age;
struct student *next;
};
int n=0;

struct student *initlist_sq1(void){
struct student *p1,*p2,*head;
char c;
p1=p2=(struct student *)malloc(sizeof( struct student));
if(! p1)
exit (OVERFLOW);
// gets(&p1->name);
scanf("%d",&p1->age);
head=NULL;
while(p1->name!=NULL){
n++;
if( n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(sizeof( struct student));
// gets(&p1->name);
scanf("%d",p1->age);
printf("Once again y/n");
scanf("%c",&c);