200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 99行不用指针 c语言贪食蛇 关于C语言指针的问题

99行不用指针 c语言贪食蛇 关于C语言指针的问题

时间:2022-06-28 13:47:02

相关推荐

99行不用指针 c语言贪食蛇 关于C语言指针的问题

#include"iostream.h"

struct

student

{

long

num;

int

score;

student

*next;

};

student

*creat();

void

print(student

*head);

student

*insert(student

*head,student

*stud);

student

*del(student

*head,long

num);

void

main()

{

student

*head=NULL,*stud;

long

num;int

score;

cout<

建立学号、成绩:"<

head=creat();

cout<

print(head);

cout<>num;

while(num>0)

{

cout<>score;

stud=new

student;

stud->num=num;

stud->score=score;

head=insert(head,stud);

cout<>num;

}

cout<

print(head);

cout<>num;

while(num>0)

{

head=del(head,num);

cout<>num;

}

cout<

print(head);

}

student

*creat()

{

student

*head,*p1,*p2;

long

num;int

n=0;

head=NULL;

p1=new

student;

cout<

cin>>num;

while(num>0)

{

n++;

p1->num=num;

cout<>p1->score;

if

(n==1)

head=p1;

p2=p1;

p1=new

student;

p2->next=p1;

cout<

cin>>num;

}

p2->next=NULL;

return(head);

}

void

print(student

*head)

{

student

*p;

p=head;

}while(p!=NULL)

{

cout<num<

"<score<

p=p->next;

}

student

*del(student

*head,long

num)

{

student

*p1,*p2;

p1=head;

if(head==NULL)

cout<

null!"<

else

if(num==head->num)

head=head->next;

else

{

while(p1->num!=num

&&

p1->next!=NULL)

{

p2=p1;p1=p1->next;}

if

(p1->num==num)

{

if(p1->next==NULL)

p2->next=NULL;

else

p2->next=p1->next;

}

else

cout<

find!"<

}

delete

p1;

return(head);

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。