数据结构实验
- 资源大小:94 K
- 上传时间:
2018-05-09
- 上传用户:123456..
- 资源积分:2 下载积分
- 标 签:
数据结构
实验
资 源 简 介
-
#include <stdio.h>
-
#include <stdlib.h> ///链式栈
-
-
typedef struct node
-
{
-
int data;
-
struct node *next;
-
}Node,*Linklist;
-
-
Linklist Createlist()
-
{
-
Linklist p;
-
Linklist h;
-
int data1;
-
scanf("%d",&data1);
-
if(data1 != 0)
-
{
-
h = (Node *)malloc(sizeof(Node));
-
h->data = data1;
-
h->next = NULL;
-
}
-
else if(data1 == 0)
-
return NULL;
-
scanf("%d",&data1);
-
while(data1 != 0)
-
{
-
p = (Node *)malloc(sizeof(Node));
-
p -> data = data1;
-
p -> next = h;
-
h = p;
-
scanf("%d",&data1);
-
}
-
return h;
-
}
-
-
void Outputlist(Node *head)
-
{
-
Linklist p;
-
p = head;
-
while(p != NULL )
-
{
-
printf("%d ",p->data);
-
p = p->next;
-
}
-
printf("\n");
-
}
-
-
void Freelist(Node *head)
-
{
-
Node *p;
-
Node *q = NULL;
-
p = head;
-
while(p != NULL)
-
{
-
q = p;
-
p = p->next;
-
free(q);
-
}
-
}
-
-
int main()
-
{
-
Node *head;
-
head = Createlist();
-
-
Outputlist(head);
-
-
Freelist(head);
-
-
return 0;
-
}
2.顺序栈
-
#include <iostream>
-
#include <stdio.h>
-
#include <stdlib.h> ///顺序栈
-
#define MaxSize 100
-
-
using namespace std;
-
-
typedef