#include <iostream> #include <stdio.head> #include <stdlib.head> #include <string.head> #define ElemType int #define max 100 using namespace std; typedef struct node1 { ElemType data; struct node1 *next; }Node1,*LinkList;//鏈棧 typedef struct { ElemType *base; int top; }SqStack;//順序棧 typedef struct node2 { ElemType data; struct node2 *next; }Node2,*LinkQueue; typedef struct node22 { LinkQueue front; LinkQueue rear; }*LinkList;//鏈隊列 typedef struct { ElemType *base; int front,rear; }SqQueue;//順序隊列 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 //1.采用鏈式存儲實現(xiàn)棧的初始化、入棧、出棧操作。 LinkList CreateStack()//創(chuàng)建棧 { LinkList top; top=NULL; return top; } bool StackEmpty(LinkList s)//判斷棧是否為空,0代表空 { if(s==NULL) return 0; else return 1; } LinkList Pushead(LinkList s,int x)//入棧 { LinkList q,top=s; q=(LinkList)malloc(sizeof(Node1)); q->data=x; q->next=top; top=q; return top; } LinkList Pop(LinkList s,int &e)//出棧 { if(!StackEmpty(s)) { printf("棧為空。"); } else { e=s->data; LinkList p=s; s=s->next; free(p); } return s; } void DisplayStack(LinkList s)//遍歷輸出棧中元素 { if(!StackEmpty(s)) printf("棧為空。"); else { wheadile(s!=NULL) { cout<<s->data<<" "; s=s->next; } cout<<endl; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 //2.采用順序存儲實現(xiàn)棧的初始化、入棧、出棧操作。 int StackEmpty(int t)//判斷棧S是否為空 { SqStack.top=t; if (SqStack.top==0) return 0; else return 1; } int InitStack() { SqStack.top=0; return SqStack.top; } int pushead(int t,int e) { SqStack.top=t; SqStack.base[++SqStack.top]=e; return SqStack.top; } int pop(int t,int *e)//出棧 { SqStack.top=t; if(!StackEmpty(SqStack.top)) { printf("棧為空."); return SqStack.top; } *e=SqStack.base[s.top]; SqStack.top--; return SqStack.top; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 //3.采用鏈式存儲實現(xiàn)隊列的初始化、入隊、出隊操作。 LinkList InitQueue()//創(chuàng)建 { LinkList head; head->rear=(LinkQueue)malloc(sizeof(Node)); head->front=head->rear; head->front->next=NULL; return head; } void deleteEle(LinkList head,int &e)//出隊 { LinkQueue p; p=head->front->next; e=p->data; head->front->next=p->next; if(head->rear==p) head->rear=head->front; free(p); } void EnQueue(LinkList head,int e)//入隊 { LinkQueue p=(LinkQueue)malloc(sizeof(Node)); p->data=e; p->next=NULL; head->rear->next=p; head->rear=p; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 //4.采用順序存儲實現(xiàn)循環(huán)隊列的初始化、入隊、出隊操作。 bool InitQueue(SqQueue &head)//創(chuàng)建隊列 { head.data=(int *)malloc(sizeof(int)); head.front=head.rear=0; return 1; } bool EnQueue(SqQueue &head,int e)//入隊 { if((head.rear+1)%MAXQSIZE==head.front) { printf("隊列已滿\n"); return 0; } head.data[head.rear]=e; head.rear=(head.rear+1)%MAXQSIZE; return 1; } int QueueLengthead(SqQueue &head)//返回隊列長度 { return (head.rear-head.front+MAXQSIZE)%MAXQSIZE; } bool deleteEle(SqQueue &head,int &e)//出隊 { if(head.front==head.rear) { cout<<"隊列為空!"<<endl; return 0; } e=head.data[head.front]; head.front=(head.front+1)%MAXQSIZE; return 1; } int gethead(SqQueue head)//得到隊列頭元素 { return head.data[head.front]; } int QueueEmpty(SqQueue head)//判斷隊列是否為空 { if (head.front==head.rear) return 1; else return 0; } void travelQueue(SqQueue head)//遍歷輸出 { wheadile(head.front!=head.rear) { printf("%d ",head.data[head.front]); head.front=(head.front+1)%MAXQSIZE; } cout<<endl; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 //5.在主函數(shù)中設(shè)計一個簡單的菜單,分別測試上述算法。 int main() { LinkList top=CreateStack(); int x; wheadile(scanf("%d",&x)!=-1) { top=Pushead(top,x); } int e; wheadile(StackEmpty(top)) { top=Pop(top,e); printf("%d ",e); }//以上是鏈棧的測試 int top=InitStack(); int x; wheadile(cin>>x) top=pushead(top,x); int e; wheadile(StackEmpty(top)) { top=pop(top,&e); printf("%d ",e); }//以上是順序棧的測試 LinkList Q; Q=InitQueue(); int x; wheadile(scanf("%d",&x)!=-1) { EnQueue(Q,x); } int e; wheadile(Q) { deleteEle(Q,e); printf("%d ",e); }//以上是鏈隊列的測試 SqQueue Q1; InitQueue(Q1); int x; wheadile(scanf("%d",&x)!=-1) { EnQueue(Q1,x); } int e; wheadile(QueueEmpty(Q1)) { deleteEle(Q1,e); printf("%d ",e); } return 0; }
標簽: 數(shù)據(jù)結(jié)構(gòu) 實驗
上傳時間: 2018-05-09
上傳用戶:123456..
1602,LCD,液晶,使用手冊 1602 = 16個字符/行 * 2行 = 像素 16*2
上傳時間: 2018-05-10
上傳用戶:phg210
數(shù)據(jù)工廠是生產(chǎn)數(shù)據(jù)的,主要應用領(lǐng)域是性能測試中的大數(shù)據(jù)量測試, 也就是性能測試數(shù)據(jù)準備階段。
標簽: 數(shù)據(jù) 工廠
上傳時間: 2018-07-01
上傳用戶:dada
Mind 的思維導圖結(jié)構(gòu)包含一個中心主題,各主要分支從中心主題向外輻射開來。除了基本的思維導圖結(jié)構(gòu)外,XMind 還提供組織結(jié)構(gòu)圖,樹狀圖,邏輯圖等。這些結(jié)構(gòu)幫助用戶在不同的使用場景中發(fā)揮了重要作用。更為重要的是,所有的這些結(jié)構(gòu)可以同時在一張思維導圖中使用!
標簽: 思維導圖構(gòu)建
上傳時間: 2018-09-03
上傳用戶:zhangyarong
XMind 的思維導圖結(jié)構(gòu)包含一個中心主題,各主要分支從中心主題向外輻射開來。除了基本的思維導圖結(jié)構(gòu)外,XMind 還提供組織結(jié)構(gòu)圖,樹狀圖,邏輯圖等。這些結(jié)構(gòu)幫助用戶在不同的使用場景中發(fā)揮了重要作用。更為重要的是,所有的這些結(jié)構(gòu)可以同時在一張思維導圖中使用!
標簽: 思維導圖
上傳時間: 2018-09-03
上傳用戶:zhangyarong
本資料是面向 CAN 總線初學者的 CAN 入門書。對 CAN 是什么、 CAN 的特征、標準規(guī)格下的位置分布等、CAN 的概要及 CAN 的協(xié)議進行了說明。
上傳時間: 2019-01-09
上傳用戶:waferhit
Introduction jSMPP is a java implementation (SMPP API) of the SMPP protocol (currently supports SMPP v3.4). It provides interfaces to communicate with a Message Center or an ESME (External Short Message Entity) and is able to handle traffic of 3000-5000 messages per second. jSMPP is not a high-level library. People looking for a quick way to get started with SMPP may be better of using an abstraction layer such as the Apache Camel SMPP component: http://camel.apache.org/smpp.html Travis-CI status: History The project started on Google Code: http://code.google.com/p/jsmpp/ It was maintained by uudashr on Github until 2013. It is now a community project maintained at http://jsmpp.org Release procedure mvn deploy -DperformRelease=true -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging -Dgpg.passphrase=<yourpassphrase> log in here: https://oss.sonatype.org click the 'Staging Repositories' link select the repository and click close select the repository and click release License Copyright (C) 2007-2013, Nuruddin Ashr uudashr@gmail.com Copyright (C) 2012-2013, Denis Kostousov denis.kostousov@gmail.com Copyright (C) 2014, Daniel Pocock http://danielpocock.com Copyright (C) 2016, Pim Moerenhout pim.moerenhout@gmail.com This project is licensed under the Apache Software License 2.0.
上傳時間: 2019-01-25
上傳用戶:dragon_longer
IP2161是一款集成 7 種、用于 USB 輸出端口的快充協(xié)議 IC,支持 7 種快充協(xié)議,包括 HVDCP QC3.0/QC2.0,F(xiàn)CP,AFC, SFCP,APPLE 2.4A,BC1.2 以及三星 2.0A。 聯(lián)系人:唐云先生(銷售工程) 手機:13530452646(微信同號) 座機:0755-33653783 (直線) Q Q: 2944353362
標簽: IP2161 快充協(xié)議 IC
上傳時間: 2019-03-18
上傳用戶:lryang
MATLAB仿真飛行器編隊算法
上傳時間: 2019-05-14
上傳用戶:是麗麗啊
破解工具和全套軟件是分開的2個鏈接,如果鏈接失效私信 各位動動你們金貴的手指給點愛心和懸賞或者幣都可以,想去影視區(qū)看看電影 adobe全套軟件 鏈接:https://pan.baidu.com/s/1AzuJxfIFWmEqcyWa8_esDg 密碼:ngmf 破解工具 鏈接:https://pan.baidu.com/s/1IqkHZ6KuiCkM9v611hB0ZQ 密碼:mbur
上傳時間: 2019-11-06
上傳用戶:564988996
蟲蟲下載站版權(quán)所有 京ICP備2021023401號-1