物件導向的堆實現

2021-06-21 07:03:46 字數 867 閱讀 7235

自己寫的小根堆類

發現乙個問題:堆並沒有不允許出現重複元素這個性質,之前一直有錯誤的印象

當類中含有vector資料成員時,建構函式怎麼寫?答案是不寫,交給vector的預設建構函式處理.

#include #include using namespace std;

templateclass minheap

else return;}}

void siftup(int start)

else return;}}

}public:

minheap(int left, int right, t a)

void show()

void createminheap()

cout << "minheap:";

show();

}void insert(t val)

bool remove(t& elem)

int size()

};int main() ;

minheaph(0, 9, a);

h.insert(-1);

h.insert(7); //重複數,

h.insert(12);

int b[12];

for (int i = 0; i < 12; ++i)

h.remove(b[i]);

cout << "b:";

for (int i = 0; i < 12; ++i)

cout << b[i] << " ";

cout << endl;

system("pause");

return 0;

}

c實現物件導向

c語言的結構體裡面沒有函式,但是c 裡面有函式,所以今天實現乙個c語言物件導向的程式 1 封裝 include include include typedef struct cmd newcmd void run newcmd pcmd void print newcmd pcmd int main...

python物件導向 用函式實現物件導向原理

類的定義 乙個抽象的概念,儲存一些共有的屬性和特徵 物件 物件代表具體事物的特徵功能,是類的例項 物件導向程式設計 通過函式實現物件導向設計 defdog name,type,gender defjiao dog1 print 你看 s 狗再叫 dog1 name 函式的區域性作用域 defslee...

Golang中物件導向的實現

golang中沒有類 class 的概念,但是有結構 struct 的概念。在其他語言 比如c 中,屬性是與方法繫結在一起的,而在go中屬性與方法是松耦合的。乙個簡單的結構 type student struct方法寫在結構的外面,比如我們要為student物件新增getter和setter,我們應...