姓名:吴振国 学号:06
上机实验三
题目一:
程序流程说明
(1)创建一个链栈,(2)编写输出,进栈出站函数,(3)编写主函数
二、程序代码
#include<>
#include<>
#define LEN sizeof(node_type)
typedef struct node
{
int data;
struct node *next;
}node_type;
typedef struct {
node_type *top;
int length;
}lstack_type;
lstack_type *create_list(void)
{
lstack_type *p;
p=(lstack_type *)malloc(sizeof(lstack_type));
p->top=NULL;
p->length=0;
return(p);
}
void print(node_type *head)
{
node_type *p;
printf("Now ,those records are:\n");
p=head;
if(head!=NULL)
{
do{
printf("%4d",p->data);
p=p->next;
}
while(p!=NULL);
}
}
int push(lstack_type *lp, int x)
{ node_type *p;
p=(node_type *)malloc(LEN);
if(p!=NULL)
{ p->data = x;
p->next = lp->top;
lp-> top = p;
lp->length++;
return(1);
}
else return(0);
}
int pop(lstack_type *lp)
{
node_type *p;
int x;
if(lp->top==NULL){
printf("stack is underflow");
return(0);
}
else{
x = lp->top->data;
p = lp->top;
lp->top = lp->top->next;
lp->length--;
free(p);
return(true);
}
}
软件技术基础--上机实验三 来自淘豆网www.taodocs.com转载请标明出处.