代码
#include
<
iostream
>
using
namespace
std;
struct
student
//
定义结构体
{
int
data; student
*
next;};
//
创建链表
student
*
CreateList(){ student
*
head
=
NULL; student
*
p
=
new
student; cin
>>
p
->
data; student
*
end
=
p;
while
(p
->
data
!=
0
) {
if
(head
==
NULL) head
=
p;
else
end
->
next
=
p; end
=
p; p
=
new
student; cin
>>
p
->
data; } end
->
next
=
NULL; delete p;
return
(head);}
int
main(){ student
*
Head
=
CreateList(); student
*
temp
=
Head;
while
(temp
!=
NULL) { cout
<<
temp
->
data
<<
"
"
; temp
=
temp
->
next; }
return
1
; }
转载于:https://www.cnblogs.com/ManMonth/archive/2010/06/23/1763951.html
转载请注明原文地址: https://win8.8miu.com/read-15496.html