日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C++數(shù)據(jù)結(jié)構(gòu)學(xué)習(xí)之棧和隊列

C++數(shù)據(jù)結(jié)構(gòu)學(xué)習(xí)中,順序表示的隊列,必須預(yù)先分配空間,并且空間大小受限,使用起來限制比較多。而且,由于限定存取位置,順序表示的隨機存取的優(yōu)點就沒有了,所以,鏈?zhǔn)浇Y(jié)構(gòu)應(yīng)該是***。

開平網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),開平網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為開平上1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的開平做網(wǎng)站的公司定做!

  棧的定義和實現(xiàn)

 
 
 
  1. #ifndef Stack_H
  2. #define Stack_H 
  3. #include "List.h"
  4. template  class Stack : List //棧類定義  
  5. {
  6.  public:
  7.   void Push(Type value)
  8.   {
  9.    Insert(value);
  10.   }
  11.  Type Pop()
  12.  {
  13.   Type p = *GetNext();
  14.   RemoveAfter();
  15.   return p;
  16.  }
  17.  Type GetTop()
  18.  {
  19.   return *GetNext();
  20.  }
  21.  List  ::MakeEmpty;  
  22.  List  ::IsEmpty;  
  23. };
  24. #endif

  隊列的定義和實現(xiàn)

 
 
 
  1. #ifndef Queue_H
  2. #define Queue_H
  3. #include "List.h"
  4. template  class Queue : List //隊列定義  
  5. {
  6.  public:
  7.   void EnQueue(const Type &value)
  8.   {
  9.    LastInsert(value);
  10.   }
  11.  Type DeQueue()
  12.  { 
  13.   Type p = *GetNext();
  14.   RemoveAfter();
  15.   IsEmpty();
  16.   return p;
  17.  }
  18.  Type GetFront()
  19.  {
  20.   return *GetNext();
  21.  }
  22.  List  ::MakeEmpty;  
  23.  List  ::IsEmpty;  
  24. };
  25. #endif

  測試程序

 
 
 
  1. #ifndef StackTest_H
  2. #define StackTest_H
  3. #include "Stack.h"
  4. void StackTest_int()
  5. {
  6.  cout << endl << "整型棧測試" << endl;
  7.  cout << endl << "構(gòu)造一個空棧" << endl;
  8.  Stack a;
  9.  cout << "將1~20入棧,然后再出棧" << endl;
  10.  for (int i = 1; i <= 20; i++) a.Push(i);
  11.   while (!a.IsEmpty()) cout << a.Pop() << ' ';
  12.   cout << endl;
  13. }
  14. #endif
  15. #ifndef QueueTest_H
  16. #define QueueTest_H
  17. #include "Queue.h"
  18. void QueueTest_int()
  19. {
  20.  cout << endl << "整型隊列測試" << endl;
  21.  cout << endl << "構(gòu)造一個空隊列" << endl;
  22.  Queue a;
  23.  cout << "將1~20入隊,然后再出隊" << endl;
  24.  for (int i = 1; i <= 20; i++) a.EnQueue(i);
  25.  while (!a.IsEmpty()) cout << a.DeQueue() << ' ';
  26.  cout << endl;
  27. }
  28. #endif

  沒什么好說的,你可以清楚的看到,在單鏈表的基礎(chǔ)上,棧和隊列的實現(xiàn)是如此的簡單。

  如讀者希望繼續(xù)閱讀棧和隊列的應(yīng)用,請閱讀拓展文章C++數(shù)據(jù)結(jié)構(gòu)學(xué)習(xí)之棧的應(yīng)用和C++數(shù)據(jù)結(jié)構(gòu)學(xué)習(xí)之隊列的應(yīng)用 。


當(dāng)前標(biāo)題:C++數(shù)據(jù)結(jié)構(gòu)學(xué)習(xí)之棧和隊列
URL網(wǎng)址:http://www.5511xx.com/article/dhghgco.html