#include <stdio.h>
#include <string.h>
typedef int data;
typedef struct Stack
{
data elements;
struct Stack *next;
}stack;
stack *creat(int i)
{
stack *top,*s;
int k=0,j=0;
while(k<i)
{
s= (stack *)malloc(sizeof(stack));
scanf("%d",&s->elements);
if(top = NULL)
{
top = s;
}
else
{
s->next = top;
top = s;
}
if(!top->next)
{
printf("NULL.\n");
}
printf("%d \n",top->elements);
k++;
}
return top;
}
void push(stack *top,data e)
{
stack *s;
s = (stack *)malloc(sizeof(stack));
s->elements = e;
s->next = top;
top =s;
}
stack *POPs(stack *top)
{
stack *s;
s= top->next;
free(top);
return s;
}
void output(stack *top)
{
stack *s;
s = top;
int i=0;
while(i++<5)
{
printf("%d | ",s->elements);
s = s->next;
}
putchar(*\n*);
}
int main(void)
{
stack *top;
top =creat(5);
output(top);
return 0;
}
#include <string.h>
typedef int data;
typedef struct Stack
{
data elements;
struct Stack *next;
}stack;
stack *creat(int i)
{
stack *top,*s;
int k=0,j=0;
while(k<i)
{
s= (stack *)malloc(sizeof(stack));
scanf("%d",&s->elements);
if(top = NULL)
{
top = s;
}
else
{
s->next = top;
top = s;
}
if(!top->next)
{
printf("NULL.\n");
}
printf("%d \n",top->elements);
k++;
}
return top;
}
void push(stack *top,data e)
{
stack *s;
s = (stack *)malloc(sizeof(stack));
s->elements = e;
s->next = top;
top =s;
}
stack *POPs(stack *top)
{
stack *s;
s= top->next;
free(top);
return s;
}
void output(stack *top)
{
stack *s;
s = top;
int i=0;
while(i++<5)
{
printf("%d | ",s->elements);
s = s->next;
}
putchar(*\n*);
}
int main(void)
{
stack *top;
top =creat(5);
output(top);
return 0;
}