偶写的链表、堆栈、队列的集合操作

2016-02-19 13:27 36 1 收藏

下面是个偶写的链表、堆栈、队列的集合操作教程,撑握了其技术要点,学起来就简单多了。赶紧跟着图老师小编一起来看看吧!

【 tulaoshi.com - 编程语言 】

偶写了一个程序,它的功能是将链表、堆栈、和队列进行集合操作,可以处理一般的插入N个元素,删除N个元素,以及入栈出栈的问题。
  --------本程序的最大的特点是能够准确的显示当前的集合操作的各个元素的状态,并且能够将队列的数据以堆栈的格式输出,同样也支持将堆栈的数据以队列的格式显示出来,报错功能也不错,程序的最后将我们开辟的所有的结点空间全部释放掉。偶觉得,数据结构,说白了就是个哪个先进哪个先出的问题,大家觉得呢??-----------------偶的QQ:37170732,欢迎喜欢编程的同学加我,非凡是爱好Win32和MFC的同学,大家一起来讨论哦!-----------------------------下面是程序的代码------------------------------------------
  
  #include stdio.h
  #include conio.h
  #define NULL 0
  typedef int DataType;
  typedef strUCt Node *PNode;
  struct Node
  {
    DataType  info;
    PNode link;
  };
  struct LinkType
  {
    PNode base;
    PNode top;
  };
  typedef struct LinkType *PLinkType;
  
  PLinkType CreatePointer(void)
  { PLinkType pltype;
    pltype=(PLinkType)malloc(sizeof(struct LinkType));
    if(pltype== NULL) { printf("Out of space");
       pltype=(PLinkType)realloc(sizeof(struct LinkType));}
    pltype-base=pltype-top=NULL;
    return(pltype);
  }
  
  PLinkType CreateHeadNode(PLinkType pltype)
  { PNode paque;
    paque=(PNode)malloc(sizeof(struct Node));
    if(paque==NULL){
    printf("Out of space");
    paque=(PNode)realloc(sizeof(struct Node));}
    else if(paque!= NULL) pltype-base=pltype-top=paque;
    pltype-top-link-link=NULL;
  
    return(pltype);
  }
  
  PLinkType push_Type(PLinkType pltype,DataType n)
  { PNode p;
    int j;
    j=0;
    printf("Input %d integer:",n);
    while(jn) {
     pltype-top-link=(PNode)malloc(sizeof(struct Node));
     if(pltype-top-link==NULL) {
  printf("Out of space");
  pltype-top-link=(PNode)realloc(sizeof(struct Node));}
     else { while(pltype-top-link!=NULL){
     pltype-top-link-link=NULL;
     pltype-top=pltype-top-link;
     scanf("%d",&pltype-top-info);
     j++;}}}
   return(pltype);
  }
  
  PLinkType print_Type(PLinkType pltype)
  { PNode temp;
    temp=pltype-base;
    if(temp!=pltype-top){
     printf("");
     while(temp!=pltype-top) {
   printf("%d",temp-link-info);
   temp=temp-link;}}
    else printf("empty");
    return(pltype);
  }
  
  PLinkType pop_Type(PLinkType pltype)
  {
    while(pltype-base!=pltype-top) {
     printf("%d",pltype-base-info);
     pltype-base=pltype-base-link;}
    return(pltype);
  }
  
  PLinkType de_Type(PLinkType pltype, DataType j)
  {int i;
   i=0;
   if(pltype-base!=pltype-top){
      printf("The pop type list is:");
      while(pltype-base!=pltype-top &&ij){
     printf("%d",pltype-base-link-info);
     pltype-base=pltype-base-link;
     i++;}
      printf("%d number(s) has been detyped",i);}
   if(pltype-base==pltype-top){
      printf("All the type have been detyped");}
   return(pltype);
  }
  
  PLinkType pop_Stack(PLinkType pltype,DataType j)
  {PNode temp;
   int i;
   i=0;
   if(pltype-top!=pltype-base){
     printf("The pop stack is:");
     while(pltype-top!=pltype-base &&ij){
     temp=pltype-base;
     if(temp-link!=pltype-top){
      while(temp-link != pltype-top) temp=temp-link;
      pltype-top-link=pltype-top;
      pltype-top=temp;
      printf("%d",pltype-top-link-info);
      i++;}
   else{pltype-top-link=pltype-top;
        pltype-top=temp;
        printf("%d",pltype-top-link-info);
        i++;}}
   printf("%d number(s) have been poped",i);
     return(pltype);}
   return(pltype);
  }
  
  PLinkType free_all(PLinkType pltype)
  {PNode temp;
   while(pltype-base!=pltype-top){
         temp=pltype-top;
         pltype-base=pltype-base-link;
         free(temp);}
   free(pltype-base);
   free(pltype);
   printf("All the Nodes and pointer have been freed");
  }
  
  void main()
  { PLinkType pltype;
    PNode pastack;
    int j1,j2,j3,j4,j5,k;
    int m1,m2,m3,m4,m5,n1,n2,n3,n4,n5;
    pltype=CreatePointer();
    CreateHeadNode(pltype);
    printf("please choose the type of data struct:");
    printf("1:linklist, 2:linkstack,3:linkqueue,0:to exit");
    scanf("%d",&k);
    while(k!=0){
    switch(k){
    case 1:{printf("Input the length of linklist:");
    scanf("%d",&m1);
    while(m11 ){
      printf("The length is illegal,please input again");
      scanf("%d",&m1);}
    push_Type(pltype,m1);
    printf("The link list is");
    print_Type(pltype);
    printf("If you want to enlist or delist,please choose");
    printf("1: to enlist,  2: to delist,   0:to struct choose");
    scanf("%d",&m2);
    while(m2!=0){
    switch(m2){
    case 1:{printf("Input the length of the list");
   scanf("%d",&m3);
   while(m31 ){
   printf("The length is illegal,please input again");
   scanf("%d",&m3);}
   push_Type(pltype,m3);
   printf("The link list is:");
   print_Type(pltype);} break;
    case 2:{if(pltype-base==pltype-top){
    printf("The link list is empty");}
   else{
     printf("please input number(s) that you want to delist:");
     scanf("%d",&m4);
     de_Type(pltype,m4);
     printf("The&n
  

来源:https://www.tulaoshi.com/n/20160219/1604357.html

延伸阅读
3.链表节点的插入 4.链表节点的删除 3.链表节点的插入 解:     1) 首先声明一个新节点供输入要插入节点的内容     2) 由用户输入一个节点内容(Key),表示欲插入在哪一个节点之后     3) 持续往下一个节点,直到节点内容Key或节点指针为NULL为止(即找不到...
标签: SQLServer
包括安装时提示有挂起的操作、收缩数据库、压缩数据库、转移数据库给新用户以已存在用户权限、检查备份集、修复数据库等 (一)挂起操作 在安装Sql或sp补丁的时候系统提示之前有挂起的安装操作,要求重启,这里往往重启无用,解决办法: 到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager 删除PendingFileRenameOperatio...
本文介绍Fireworks中一些比较新颖实用的操作技巧,一定能帮助大家在设计中轻松提高效率。 技巧1:使用键盘的方向键移动对象时,按住【Shift】键不放,每次可以移动10个象素。 技巧2:使用【指针】工具移动对象时,按住【Shift】键不放,可以保证其水平或垂直移动。 技巧3:按住【Alt】键不放拖拽某个对象,即可对其进...
标签: Web开发
删除字符串首尾空字符:$.trim() 像很多高级语言都提供了类似的函数,jQuery类库也提供了这样的函数。具体用法:$.trim(value)从已传入的字符串里删除首尾空白字符并返回结果。 对属性和集合进行迭代: 在JavaScript操作数组和对象可以采用下面的方法: var anArray = ['one','two','three']; for(var n = 0; n anArray.length; n++){......
本课主题: 实验二 循环链表实验 教学目的: 把握单向链表的实现方法 教学重点: 单向链表的存储表示及操作 教学难点: 单向链表的操作实现 授课内容: 一、单向链表的存储表示 C源程序 二、单向链表的基本操作 C源程序

经验教程

244

收藏

16
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部