#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
struct node *next;
}node, linklist;
node * hua_linklist( )
{
linklist *L = 0 ;
printf("输入数组,生成“先进后出”的单链表。当输入9则结束输入:/n");
node *s;
int x;
do{
scanf("%d", &x);
s = (node *)malloc(sizeof(node));
s -> data = x;
s -> next = L;
L = s;
}while(x - 9);
return L;
}
void hua_output(linklist *L)
{
node *p;
p = L;
printf("表中各节点为:");
while(p != 0){
printf("/t%d", p -> data);
p = p -> next;
}
p = L;
/*node *q;
q = (node *)malloc(sizeof(node));*/
printf("/n首节点为:%d", p -> data);
while( p -> next != 0){
p = p ->next;
if(p -> next == 0)
printf("/n尾节点为:%d/n", p -> data);
}
/*q ->data = p -> data;
p=p -> next;
}
printf("%d", q -> data);*/
}
void main ( )
{
linklist *L;
L = hua_linklist( );
hua_output(L);
}