亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

蟲(chóng)蟲(chóng)首頁(yè)| 資源下載| 資源專(zhuān)輯| 精品軟件
登錄| 注冊(cè)

enqueue

  • 大頂堆實(shí)現(xiàn)一個(gè)優(yōu)先隊(duì)列。對(duì)于隊(duì)列的操作應(yīng)該至少支持下列幾種指令: Void enqueue[int ObjectID, int Priority] Int dequeue[]

    大頂堆實(shí)現(xiàn)一個(gè)優(yōu)先隊(duì)列。對(duì)于隊(duì)列的操作應(yīng)該至少支持下列幾種指令: Void enqueue[int ObjectID, int Priority] Int dequeue[] Void changeweight[int ObjectID, int newPriority]

    標(biāo)簽: int ObjectID Priority enqueue

    上傳時(shí)間: 2013-12-28

    上傳用戶(hù):lunshaomo

  • 在c51上實(shí)現(xiàn)的隊(duì)列,包括InitQueue

    在c51上實(shí)現(xiàn)的隊(duì)列,包括InitQueue,enqueue,DelQueue,查詢(xún)隊(duì)列等等,用于在鍵盤(pán)輸入顯示上,隊(duì)列很有效!

    標(biāo)簽: InitQueue c51 隊(duì)列

    上傳時(shí)間: 2016-06-13

    上傳用戶(hù):ynsnjs

  • 鏈?zhǔn)疥?duì)列的存儲(chǔ)結(jié)構(gòu)以及功能實(shí)現(xiàn)

    鏈?zhǔn)疥?duì)列的存儲(chǔ)結(jié)構(gòu)以及功能實(shí)現(xiàn),有QueueTraverse(),enqueue(),DeQueue()等子函數(shù)。

    標(biāo)簽: 存儲(chǔ)結(jié)構(gòu) 隊(duì)列

    上傳時(shí)間: 2017-09-01

    上傳用戶(hù):爺?shù)臍赓|(zhì)

  • 數(shù)據(jù)結(jié)構(gòu)實(shí)驗(yàn)

    #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;//鏈隊(duì)列 typedef struct { ElemType *base; int front,rear; }SqQueue;//順序隊(duì)列 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.采用鏈?zhǔn)酱鎯?chǔ)實(shí)現(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.采用順序存儲(chǔ)實(shí)現(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.采用鏈?zhǔn)酱鎯?chǔ)實(shí)現(xiàn)隊(duì)列的初始化、入隊(duì)、出隊(duì)操作。 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)//出隊(duì) { 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)//入隊(duì) { 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.采用順序存儲(chǔ)實(shí)現(xiàn)循環(huán)隊(duì)列的初始化、入隊(duì)、出隊(duì)操作。 bool InitQueue(SqQueue &head)//創(chuàng)建隊(duì)列 { head.data=(int *)malloc(sizeof(int)); head.front=head.rear=0; return 1; } bool enqueue(SqQueue &head,int e)//入隊(duì) { if((head.rear+1)%MAXQSIZE==head.front) { printf("隊(duì)列已滿\n"); return 0; } head.data[head.rear]=e; head.rear=(head.rear+1)%MAXQSIZE; return 1; } int QueueLengthead(SqQueue &head)//返回隊(duì)列長(zhǎng)度 { return (head.rear-head.front+MAXQSIZE)%MAXQSIZE; } bool deleteEle(SqQueue &head,int &e)//出隊(duì) { if(head.front==head.rear) { cout<<"隊(duì)列為空!"<<endl; return 0; } e=head.data[head.front]; head.front=(head.front+1)%MAXQSIZE; return 1; } int gethead(SqQueue head)//得到隊(duì)列頭元素 { return head.data[head.front]; } int QueueEmpty(SqQueue head)//判斷隊(duì)列是否為空 { 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è)計(jì)一個(gè)簡(jiǎn)單的菜單,分別測(cè)試上述算法。 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); }//以上是鏈棧的測(cè)試 int top=InitStack(); int x; wheadile(cin>>x) top=pushead(top,x); int e; wheadile(StackEmpty(top)) { top=pop(top,&e); printf("%d ",e); }//以上是順序棧的測(cè)試 LinkList Q; Q=InitQueue(); int x; wheadile(scanf("%d",&x)!=-1) { enqueue(Q,x); } int e; wheadile(Q) { deleteEle(Q,e); printf("%d ",e); }//以上是鏈隊(duì)列的測(cè)試 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; }

    標(biāo)簽: 數(shù)據(jù)結(jié)構(gòu) 實(shí)驗(yàn)

    上傳時(shí)間: 2018-05-09

    上傳用戶(hù):123456..

主站蜘蛛池模板: 铁岭县| 司法| 资阳市| 太湖县| 洮南市| 枞阳县| 宝应县| 海原县| 宝鸡市| 桐柏县| 漯河市| 金坛市| 巴林右旗| 郸城县| 田东县| 新巴尔虎左旗| 静宁县| 禄丰县| 阜南县| 沾化县| 娱乐| 甘泉县| 遂溪县| 辛集市| 醴陵市| 柳河县| 晋州市| 金川县| 阿坝| 怀集县| 铅山县| 天台县| 高安市| 泾川县| 昂仁县| 三江| 栾川县| 怀化市| 道真| 若尔盖县| 灯塔市|