陣列中插入乙個元素或者刪除乙個元素時,必須移動陣列中的元素,從而使動態列表的順序儲存低效。鍊錶可以解決這一問題,它由資料和乙個指向下乙個節點的指標組成。基本的操作有構造、判空、插入、刪除和遍歷。
程式如下:
#include
using namespace std;
template
class list
public:
datatype data;
node* next;
};private:
node* head;
};template
list
::list()
template
bool list
::empty()const
template
void
list
::insert(datatype & value)
else
n->next = p;
pre->next = n;}}
}template
void
list
::delete(datatype & item)
else
if (p !=
null)
else
cout <<
"item does not exist in the list!"
<< endl;}}
}template
void
list
::display()const
}}
c 鍊錶的實現
author jacky ma date 23th,may,07 主要實現 1 鍊錶的建立,2 逆置 3 排序 4 有序鍊錶的歸併 5 兩鍊錶連線 6 迴圈鍊錶的判定 include include using namespace std 鍊錶節點結構 struct linknode 建立單鏈表 l...
c的鍊錶實現
複習了單向鍊錶 雙向鍊錶,中注釋不多,但基本從函式名字就可以知道函式的作用。雙向鍊錶中的前後節點中的思路是按照linux核心中思路寫的。gcc 7.4.0 include include typedef struct node lnode,llist,node void insert llist l...
鍊錶C 實現
node.h 第乙個檔案 ifndef node h define node h define true 1 define false 0 define ok 1 define error 0 define null 0 define flag 1 class node endif node h l...