线性表
线性表的顺序表示和实现
-
线性表的顺序储存结构
-
线性表的数据结构定义
-
线性表的插入
-
线性表的删除
-
线性表的归并
-
优缺点
线性表的链式表示和实现
-
线性链表的逻辑状态
-
线性链表的数据结构定义
-
取链表中第i个元素
-
链表的插入
-
链表的删除
-
链表的逆序插入
-
链表归并
-
链表多项式合并
-
优缺点
-
简单链表类的实现
#include <iostream> using namespace std; class List_Node { public: List_Node *next; int value; }; class List_ { public: List_Node *begin; List_() { begin = new List_Node(); begin->next = NULL; } // begin->next, i = 0 bool link_list_insert_node(int i, int value) { List_Node *node = this->begin; List_Node *insert_node = new List_Node(); List_Node *tmp = new List_Node(); while(node && i--) { node = node->next; } if(!node && i > 0) return false; tmp = node->next; node->next = insert_node; insert_node->next = tmp; insert_node->value = value; return true; } // begin->next, i = 1 bool link_list_delect_node(int i) { List_Node *node = this->begin; while(node && i--) { node = node->next; } if(!node && i > 0) return false; node->next = node->next->next; return true; } int link_list_get_length() { List_Node *node = this->begin->next; int cnt = 0; while(node) { cnt++; node = node->next; } return cnt; } void link_list_print() { List_Node *node = this->begin; while(node) { if(node != this->begin) cout << node->value << " "; node = node->next; } cout << endl; return ; } int link_list_get_index_value(int i) { List_Node *node = begin->next; while(node && i--) { node = node->next; } if(!node && i > 0) return -1; return node->value; } }; int main() { // List_Node *n = new List_Node(); List_ l = List_(); l.link_list_print(); int n; cin >> n; for(int i = 0; i < n; i++) { int tmp; cin >> tmp; l.link_list_insert_node(i, tmp); } cout << "link list print: " << endl; l.link_list_print(); cout << "link list lenght: " << l.link_list_get_length() << endl; l.link_list_delect_node(2); cout << "link list print: " << endl; l.link_list_print(); return 0; }