資料結構經典演算法彙總

2021-05-23 05:12:52 字數 1890 閱讀 6811

迴圈佇列:(除錯成功)

#include "iostream.h"

class ssqueue

~ssqueue() {}

int insert(const int& item )

if(isfull())

int  out()

int getsize()

int isempty()                     //empty retrun 1

int isfull()                    //full return 1

int getfront()

int getrear()

return data[rear-1]; }

void print()

int count()

}; #include "iostream.h"

int main(int argc, char* argv)

cout<<"the front and the rear is/n";

cout<

break;

case 2:

cout<<"

請輸入要出隊元素的個數

/n";

cin>>nu;

for(i=0;i

break;

case 3:  cout<

case 4:  cout<

case 5:  q.print(); cout<

case 6:  cout<

case 7:  cout<

default:  cout<<"

你的輸入有誤!請重試

"< }

} return 0; }

迴圈模板佇列:(除錯成功)

templateclass ssqueue

~ssqueue() {}

int insert(const type& item )

if(isfull())

int  out()

int getsize()

int isempty()                     //empty retrun 1

int isfull()                    //full return 1

type getfront()

type getrear()

return data[rear-1]; }

void print()

int count()

}; #include"queue1.h"

#include "iostream.h"

#include "stdio.h"

int main(int argc, char* argv)

cout<<"the front and the rear is/n";

cout<

break;

case 2:

cout<<"

請輸入要出隊元素的個數

/n";

cin>>nu;

if(nu>q.getsize())

for(i=0;i

if(q.out()==0) break;

break;

case 3:  cout<

case 4:  cout<

case 5:  q.print(); cout<

case 6:  cout<

case 7:  cout<

default:  cout<<"

你的輸入有誤!請重試

"< }

} return 0; }

資料結構經典演算法

例如 4和3只出現過一次,請找出出現過一次的數。首先想到的 應該是上乙個提到的遍歷兩次取出沒有找到的相同的數字,如下 public static list findonlynum int array if j array.length if array i array j if j array.le...

經典資料結構 Hash演算法

什麼是雜湊表?雜湊表 hash table,也叫雜湊表 是根據關鍵碼值 key value 而直接進行訪問的資料結構。也就是說,它通過把關鍵碼值對映到表中乙個位置來訪問記錄,以加快查詢的速度。這個對映函式叫做雜湊函式,存放記錄的陣列叫做雜湊表。雜湊表的做法其實很簡單,就是把key通過乙個固定的演算法...

資料結構之排序演算法 彙總

排序演算法應該是最基礎的演算法了,博主面試至今沒有面試官單就乙個排序演算法讓寫個 什麼的。本篇小博先對常見的排序演算法進行一下總結,方便日後檢視吧。主要內容包括 氣泡排序 快速排序 選擇排序 堆排序 插入排序 希爾排序 歸併排序。一 氣泡排序 如下 public static int bubbles...