国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

偶寫的鏈表、堆棧、隊(duì)列的集合操作

2019-11-17 05:33:47
字體:
供稿:網(wǎng)友
偶寫了一個(gè)程序,它的功能是將鏈表、堆棧、和隊(duì)列進(jìn)行集合操作,可以處理一般的插入N個(gè)元素,刪除N個(gè)元素,以及入棧出棧的問題。
--------本程序的最大的特點(diǎn)是能夠準(zhǔn)確的顯示當(dāng)前的集合操作的各個(gè)元素的狀態(tài),并且能夠?qū)㈥?duì)列的數(shù)據(jù)以堆棧的格式輸出,同樣也支持將堆棧的數(shù)據(jù)以隊(duì)列的格式顯示出來,報(bào)錯(cuò)功能也不錯(cuò),程序的最后將我們開辟的所有的結(jié)點(diǎn)空間全部釋放掉。偶覺得,數(shù)據(jù)結(jié)構(gòu),說白了就是個(gè)哪個(gè)先進(jìn)哪個(gè)先出的問題,大家覺得呢??-----------------偶的QQ:37170732,歡迎喜歡編程的同學(xué)加我,非凡是愛好Win32和MFC的同學(xué),大家一起來討論哦!-----------------------------下面是程序的代碼------------------------------------------

#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) {      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/n");
  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",n);
  while(j<n) {
   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("/n");
   while(temp!=pltype->top) {
 printf("%d/t",temp->link->info);
 temp=temp->link;}}
  else printf("empty");
  return(pltype);
}

PLinkType pop_Type(PLinkType pltype)
{
  while(pltype->base!=pltype->top) {
   printf("%d/t",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:/n");
    while(pltype->base!=pltype->top &&i<j){
   printf("%d/t",pltype->base->link->info);
   pltype->base=pltype->base->link;
   i++;}
    printf("/n%d number(s) has been detyped",i);}
 if(pltype->base==pltype->top){
    printf("/nAll 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:/n");
   while(pltype->top!=pltype->base &&i<j){
   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/t",pltype->top->link->info);
    i++;}
 else{pltype->top->link=pltype->top;
      pltype->top=temp;
      printf("%d/t",pltype->top->link->info);
      i++;}}
 printf("/n%d number(s) have been poped/n",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/n");
}

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:/n");
  printf("1:linklist, 2:linkstack,3:linkqueue,0:to exit/n");
  scanf("%d",&k);
  while(k!=0){
  switch(k){
  case 1:{printf("Input the length of linklist:/n");
  scanf("%d",&m1);
  while(m1<1 ){
    printf("The length is illegal,please input again/n");
    scanf("%d",&m1);}
  push_Type(pltype,m1);
  printf("The link list is");
  print_Type(pltype);
  printf("/nIf you want to enlist or delist,please choose/n");
  printf("1: to enlist,  2: to delist,   0:to struct choose/n");
  scanf("%d",&m2);
  while(m2!=0){
  switch(m2){
  case 1:{printf("Input the length of the list/n");
 scanf("%d",&m3);
 while(m3<1 ){
 printf("The length is illegal,please input again/n");
 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/n");}
 else{
   printf("please input number(s) that you want to delist:/n");
   scanf("%d",&m4);
   de_Type(pltype,m4);
   printf("/nThe&n


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 福海县| 广德县| 哈密市| 邯郸市| 雷州市| 剑川县| 大姚县| 江都市| 四川省| 海林市| 五原县| 赣州市| 恩平市| 横峰县| 封开县| 洪江市| 资兴市| 康保县| 葵青区| 屯门区| 无棣县| 岢岚县| 德惠市| 卓尼县| 政和县| 天镇县| 怀柔区| 胶州市| 旺苍县| 化德县| 专栏| 女性| 普安县| 康马县| 监利县| 新干县| 华亭县| 汤原县| 沧州市| 若尔盖县| 临湘市|