亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
  • 數據結構是指 一種或多種特定關系的數據元素的集合
    查看全部
    0 采集 收起 來源:課程簡介

    2016-06-02

  • 模擬排號機,只需改動一下內容,運行結果如圖 void MyQueue::QueueTraverse () { for(int i=m_iHead;i<m_iQueueLen+m_iHead;i++)//m_iQueueLen+m_iHead保證循環次數不會出錯,防止當頭為1,長度為3時只能循環兩次,隊列長度指揮循環次數 { m_pQueue[i%m_iQueueCapacity].printInfo ();//直接調用類中有的打印函數,不需要再用cout cout<<"前面還有"<<(i-m_iHead)<<"人"<<endl;//模擬排號機 } }
    查看全部
  • 主函數中的應用: #include<iostream> #include<stdlib.h> #include"MyQueue.h" #include"Customer.h" using namespace std; int main(void) { MyQueue *p=new MyQueue(4); Customer c1("marry",20);//因為不再是int類型所以要定義對象 Customer c2("jack",22); Customer c3("tom",24); p->EnQueue (c1); p->EnQueue (c2); p->EnQueue (c3); p->QueueTraverse (); //在隊列中刪除元素并且獲得元素的值 Customer c4("",0);//定義一個這樣的元素c4,c4是一個沒有其他值得對象,用這個對象來獲取隊列的第一個元素,相當于之前的int e=0; p->DeQueue (c4);//把第一個元素給c4,在刪掉第一個元素 c4.printInfo ();//打印c4(即第一個元素) p->QueueTraverse ();//遍歷剩余兩個 delete p; p=NULL; return 0; }
    查看全部
  • 環形隊列的實際應用,定義customer類 #ifndef CUSTOMER_H #define CUSTOMER_H #include<string> using namespace std; class Customer { public: Customer(string name="",int age=0);//需要有默認構造函數去使隊列的構造函數成立,每個參數賦初值 void printInfo() const; private: string m_strName; int m_iAge; }; #endif #include<iostream> #include<stdlib.h> #include<string> #include"Customer.h" using namespace std; Customer::Customer(string name,int age) { m_strName=name; m_iAge=age; } void Customer::printInfo() const { cout<<"名字"<<m_strName<<endl; cout<<"年齡"<<m_iAge<<endl; cout<<endl; } 因為不再是int類型,所以隊列類中要改變一些數據類型,函數類型,如下: (public下的)bool EnQueue(Customer element);//Customer類型的元素,下同,實現要保持一致(略) bool DeQueue(Customer &element); (private下的)Customer *m_pQueue;//Customer類型的指針 遍歷的循環體要有所改動: //實際應用循環體要有所改動 void MyQueue::QueueTraverse () { for(int i=m_iHead;i<m_iQueueLen+m_iHead;i++)//m_iQueueLen+m_iHead保證循環次數不會出錯,防止當頭為1,長度為3時只能循環兩次,隊列長度指揮循環次數 { m_pQueue[i%m_iQueueCapacity].printInfo ();//直接調用類中有的打印函數,不需要再用cout } }
    查看全部
  • 接圖片代碼: p->QueueTraverse ();//發現至此不能遍歷出來,因此遍歷實現有誤,需更正 【更正: void MyQueue::QueueTraverse () { for(int i=m_iHead;i<m_iQueueLen+m_iHead;i++)//m_iQueueLen+m_iHead保證循環次數不會出錯,防止當頭為1,長度為3時只能循環兩次,隊列長度指揮循環次數 { //cout<< m_pQueue[i%m_iQueueLen] <<endl;//防止下標i溢出,環形隊列頭不一定從[0]開始 cout<< m_pQueue[i%m_iQueueCapacity] <<endl;//更正應對m_iQueueCapacity取余,對常數容量取余 } cout<<endl;//為了清晰 }】 p->ClearQueue (); p->QueueTraverse (); p->EnQueue (20); p->EnQueue (30); p->QueueTraverse (); delete p; p=NULL; return 0; }
    查看全部
    0 采集 收起 來源:環形隊列檢測

    2018-03-22

  • 環形隊列實現部分二:(重點部分) bool MyQueue::EnQueue (int element) { if(QueueFull()){return false;} else { m_pQueue[m_iTail]=element; m_iTail++; m_iTail=m_iTail%m_iQueueCapacity;//防止下標溢出 m_iQueueLen++;//長度隨時改變 return true;//告訴系統插入成功 } } bool MyQueue::DeQueue (int &element) { if(QueueEmpty()){return false;} else { element=m_pQueue[m_iHead];//首元素摘出 m_iHead++;//改變頭位置 m_iHead=m_iHead%m_iQueueCapacity;//防止下標溢出 m_iQueueLen--;//減少個數 return true; } } void MyQueue::QueueTraverse () { for(int i=m_iHead;i<m_iQueueLen;i++) { cout<< m_pQueue[i%m_iQueueLen] <<endl;//防止下標i溢出,環形隊列頭不一定從[0]開始 } }
    查看全部
    0 采集 收起 來源:環形隊列檢測

    2018-03-22

  • 環形隊列實現部分一: #include"MyQueue.h" #include<iostream> using namespace std; MyQueue::MyQueue(int queueCapacity)//構造函數用來創建隊列 { m_iQueueCapacity=queueCapacity; /*m_iHead=0; m_iTail=0; m_iQueueLen=0;*/ ClearQueue(); m_pQueue=new int[m_iQueueCapacity]; } MyQueue::~MyQueue () { delete []m_pQueue; m_pQueue=NULL; } void MyQueue::ClearQueue () { m_iHead=0; m_iTail=0; m_iQueueLen=0; } bool MyQueue::QueueEmpty () const { if(m_iQueueLen==0) { return true; } else { return false; } //return m_iQueueLen==0?true:false; } int MyQueue::QueueLength () const { return m_iQueueLen; } bool MyQueue::QueueFull () const { if(m_iQueueLen==m_iQueueCapacity) {return true;} else{return false;} }
    查看全部
    0 采集 收起 來源:環形隊列檢測

    2018-03-22

  • 隊列的定義 c++//c對比 c++有自己的數據成員所以不需要參數,而要指明數據類型,因為已經指明數據類型,所以不需要visit函數(遍歷不同種類型時要用的函數)
    查看全部
  • 數據結構概念
    查看全部
    0 采集 收起 來源:課程簡介

    2016-05-25

  • 隊列 先進先出
    查看全部
    0 采集 收起 來源:隊列

    2016-05-24

  • 環形隊列,,內存沒有空著效率高;內存中的數據也不用整體移動
    查看全部
    0 采集 收起 來源:隊列

    2016-05-20

  • 環形隊列
    查看全部
    0 采集 收起 來源:隊列

    2016-05-19

  • 隊列的用途
    查看全部
    0 采集 收起 來源:隊列

    2016-05-12

  • 環形隊列
    查看全部
    0 采集 收起 來源:隊列

    2016-05-12

  • 普通隊列
    查看全部
    0 采集 收起 來源:隊列

    2016-05-12

舉報

0/150
提交
取消
課程須知
本課程是程序世界中的核心課程 由于本門課程是以C++為編碼實現的,所以需要大家熟練掌握C++語言基礎語法。
老師告訴你能學到什么?
1、什么是數據結構、什么是隊列以及隊列的實現原理 2、如何設計隊列的類,如何完善類的設計 3、如何實現隊列的相關函數 4、如何檢驗代碼的正確性,如何完善代碼 5、如何與實際相結合,利用數據結構解決實際問題

微信掃碼,參與3人拼團

微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

友情提示:

您好,此課程屬于遷移課程,您已購買該課程,無需重復購買,感謝您對慕課網的支持!