ex_1
程序:
#include<stdio.h>
#include<malloc.h>
typedef struct node
{
int data;
struct node *next;
}node_type;
typedef struct lstack_type{
node_type * top;
int length;
}lstack_type;
void show(lstack_type *stack)
{
node_type *p;
p=stack->top;
printf("the stack is :");
while(p->next!=NULL)
printf("%5d",p->data);
}
void push(lstack_type *stack,int new_data)
{
node_type *new_node;
new_node=(node_type*)malloc(sizeof(node_type));
new_node->data=new_data;
new_node->next = stack->top;
stack->top = new_node;
stack->length ++;
show(stack);
}
void pop(lstack_type *stack)
{
node_type* out;
out = stack->top;
stack->top = stack->top->next;
stack->length --;
show(stack);
free(out);
}
void main()