比較坑爹的基礎啊,大把時間浪費在建構函式上,建構函式(出生決定命運!)。
自己解決的bug,感覺還不錯。其實程式的核心是演算法,演算法建立在資料結構的基礎之上。
大部分的程式設計師現在學的基本都是規則,而不是創造。
但掌握了規則,也能創造很多財富。
重新鞏固我弱爆了的資料結構,沒敲完資料結構的程式設計師不是好領導。
注釋就不寫了,可以提問,或者建議。
執行截圖:#include#include#include "stdlib.h"
using namespace std;
class student
student(int _id,string _name,int _score)
friend ostream & operator<
linknode(){}
};templateclass list
~list()
void makeempty();
int length();
linknode*gethead()
linknode*search(t x);
linknode*locate(int i);
bool getdata(int i,t& x);
void setdata(int i,t& x);
bool insert(int i,t& x);
bool remove(int i,t& x);
bool isempty()
void output();
};templatevoid list::makeempty()
}templateint list::length()
return count;
}templatelinknode*list::search(t x)
}templatelinknode* list::locate(int i)
return current;
}templatebool list::getdata(int i,t& x)
}templatevoid list::setdata(int i,t& x)
templatebool list::insert(int i,t& x)
templatebool list::remove(int i,t& x)
templatevoid list::output()
}void main()
stu.output();
student student;//用於刪除
stu.remove(2,student);
stu.output();
student s1(123,"biubiu",12);
stu.insert(2,s1);
stu.output();
}
資料結構 單鏈表(帶頭結點)
單鏈表是一種鏈式訪問的資料結構,用一組位址任意的儲存單元存放線性表中的資料元素。鍊錶中的資料是以結點來表示的,每個結點的構成 元素 資料元素的映象 指標 指示後繼元素儲存位置 元素就是儲存資料的儲存單元,指標就是連線每個結點的位址資料。簡單講就是邏輯相鄰,物理不相鄰 帶頭結點 list.h prag...
資料結構 單鏈表 帶頭結點和不帶頭結點
1 單鏈表 通過各結點的鏈結指標來表示結點間的邏輯關係,長度可擴充,遍歷或查詢 2 只能從指標的指示的首元結點開始,跟隨鏈結指標逐個結點進行訪問,進行刪除或插 4 5 6 單鏈表的結構定義 7 typedef int datatype 8 typedef struct node 9 linknode...
資料結構篇 單鏈表倒置(帶頭結點 不帶頭結點)
初始化如圖 1.我們需要把1這個結點作為最後乙個結點,所以要把1的next指向null 2.然後我們要新建結點,指向headnext的下一位,並把headnext的下一位指向headpre,3.headpre指向headnext為下一次迴圈做準備 headpre headnext 4.如果tempn...