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

岛屿是海的疤dz

岛屿是海的疤dz

2016-02-19 13:27

下面是个偶写的链表、堆栈、队列的集合操作教程,撑握了其技术要点,学起来就简单多了。赶紧跟着图老师小编一起来看看吧!
偶写了一个程序,它的功能是将链表、堆栈、和队列进行集合操作,可以处理一般的插入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
  
展开更多 50%)
分享

猜你喜欢

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

编程语言 网络编程
偶写的链表、堆栈、队列的集合操作

偶写的链表、堆栈、队列的集合操作------的解释补充

编程语言 网络编程
偶写的链表、堆栈、队列的集合操作------的解释补充

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Linux操作系统内核中工作队列的操作

Linux Linux命令 Linux安装 Linux编程 Linux桌面 Linux软件 Linux内核 Linux管理
Linux操作系统内核中工作队列的操作

Fireworks的高级操作技巧集合

电脑网络
Fireworks的高级操作技巧集合

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

链表的C语言实现之循环链表及双向链表

编程语言 网络编程
链表的C语言实现之循环链表及双向链表

Java语言中链表和双向链表

Web开发
Java语言中链表和双向链表

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

excel2010中的时间函数运用

excel2010中的时间函数运用

螺旋矩阵

螺旋矩阵
下拉加载更多内容 ↓