虫虫首页|资源下载|资源专辑|精品软件
登录|注册

您现在的位置是:虫虫下载站 > 资源下载 > 源码 > 数据结构实验

数据结构实验

  • 资源大小:94 K
  • 上传时间: 2018-05-09
  • 上传用户:123456..
  • 资源积分:2 下载积分
  • 标      签: 数据结构 实验

资 源 简 介

  1. #include <stdio.h>  
  2. #include <stdlib.h> ///链式栈  
  3.   
  4. typedef struct node  
  5. {  
  6.     int data;  
  7.     struct node *next;  
  8. }Node,*Linklist;  
  9.   
  10. Linklist Createlist()  
  11. {  
  12.     Linklist p;  
  13.     Linklist h;  
  14.     int data1;  
  15.     scanf("%d",&data1);  
  16.     if(data1 != 0)  
  17.     {  
  18.         h = (Node *)malloc(sizeof(Node));  
  19.         h->data = data1;  
  20.         h->next = NULL;  
  21.     }  
  22.     else if(data1 == 0)  
  23.     return NULL;  
  24.     scanf("%d",&data1);  
  25.     while(data1 != 0)  
  26.     {  
  27.         p = (Node *)malloc(sizeof(Node));  
  28.         p -> data = data1;  
  29.         p -> next = h;  
  30.         h = p;  
  31.         scanf("%d",&data1);  
  32.     }  
  33.     return h;  
  34. }  
  35.   
  36. void Outputlist(Node *head)  
  37. {  
  38.     Linklist p;  
  39.     p = head;  
  40.     while(p != NULL )  
  41.     {  
  42.         printf("%d ",p->data);  
  43.         p = p->next;  
  44.     }  
  45.     printf("\n");  
  46. }  
  47.   
  48. void Freelist(Node *head)  
  49. {  
  50.     Node *p;  
  51.     Node *q = NULL;  
  52.     p = head;  
  53.     while(p != NULL)  
  54.     {  
  55.         q = p;  
  56.         p = p->next;  
  57.         free(q);  
  58.     }  
  59. }  
  60.   
  61. int main()  
  62. {  
  63.     Node *head;  
  64.     head = Createlist();  
  65.   
  66.     Outputlist(head);  
  67.   
  68.     Freelist(head);  
  69.   
  70.     return 0;  
  71. }  



2.顺序栈

[cpp] view plain copy
  1. #include <iostream>  
  2. #include <stdio.h>  
  3. #include <stdlib.h> ///顺序栈  
  4. #define MaxSize 100  
  5.   
  6. using namespace std;  
  7.   
  8. typedef

相 关 资 源