下载此文档

软件技术基础--上机实验三.docx


文档分类:高等教育 | 页数:约10页 举报非法文档有奖
1/10
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/10 下载此文档
文档列表 文档介绍
姓名:吴振国 学号: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转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数10
  • 收藏数0 收藏
  • 顶次数0
  • 上传人miao19720107
  • 文件大小115 KB
  • 时间2021-08-02