用指標實現表

2021-05-07 22:19:28 字數 1134 閱讀 4513

#include "stdafx.h"

#include"iostream.h"

templateclass list;

template

class node

;template

class list

~list();

bool empty()const

int size() const;

bool retrieve(int k,t& x) const;

int locate (const t& x)const;

list& insert(int k,const t& x);

list& erase(int k,t& x);

void print_list (ostream& out) const;

private:

node*first;

};template

list ::~list()

}template

int list::size()const

return len;

}template

bool list::retrieve (int k,t& x)

if(current)

return false; 

}template

int list::locate (const t& x)const

if(current)return index;

return 0;

}template

list& list::insert (int k,const t& x)

else

return this;

}template

list&list::erase (int k,t& x)

x=p->data;

delete p;

return *this;

}template

void list::print_list (ostream &out) const

template

ostream&operator<<(ostream &out,const list&x)

int main(int argc, char* argv)

用函式指標表實現多型

今天老師在講多型之前要我們思考一下怎麼用函式指標表實現多型,由於最近學的東西太多了,我覺得整理下來比較好,時間久了就會忘記,記下來用於以後慢慢研究。include stdafx.h include using namespace std class ca typedef void ca pshow ...

用指標處理鍊錶

用指標處理鍊錶 建立乙個簡單的鍊錶,它由3個學生資料的結點組成,要求輸出各結點中的資料 include struct student int main while p null 輸出完c結點後p的值為null,迴圈終止 return 0 寫一函式建立乙個有3名學生資料的單向動態鍊錶 include ...

用指標處理鍊錶

鍊錶概述 鍊錶是一種常見的重要的資料結構。它是動態地進行儲存分配的一種結構。鍊錶有乙個 頭指標 變數,它存放乙個位址,該位址指向乙個元素,鍊錶中每乙個元素稱為 結點,每個結點都應包括兩個部分,一為使用者需要用的實際資料,二為下乙個結點的位址。可以看出,頭指標 head 指向第乙個元素,第乙個元素又指...