/**@date:08-07-06
*@descript:單鏈表的實現與應用
**/public class linlist
public node gethead()
//定位函式
public void index(int i) throws exception
if(i==-1)
current=head.next;
int j=0;
while((current!=null)&&j
size)
index(i-1);
//新節點的next域為current.next,而current的next域為新節點
current.setnext(new node(obj,current.next));
size++;
} //刪除函式
public object delete(int i)throws exception
if(i<0||i>size-1)
index(i-1);
object obj=current.next.getelement();
//i-1個節點的next域指向i個節點的next域,讓i節點脫鏈
current.setnext(current.next.next);
size--;
return obj;
}//獲取資料元素
public object getdata(int i)throws exception
index(i);
return current.getelement();
} //獲取元素個數
public int size()
//判斷是否為空
public boolean isempty()
//主函式
public static void main(string args)
{linlist alinlist=new linlist();
linlist blinlist=new linlist();
linlist clinlist=new linlist();
int n=10;
try {
for (int i=0; i
資料結構之單鏈表
鍊錶 儲存結構的一種,包含兩個部分,資料域和指標域,相對於順序儲存結構來說,插入和刪除的演算法時間複雜度只為o 1 定義 定義 typedef struct node linklist linklist,指標指向每乙個元素 typedef struct nodenode 以下為簡單的c語言實現 in...
資料結構之單鏈表
由於順序表再插入或者刪除時需要移動大量資料,並且如果表比較大,會比較難分配連續的儲存空間導致儲存資料失敗。因此可以採用鍊錶結構,鍊錶結構是一種動態儲存分配的結構形式,可以根據需要動態的申請所需的儲存單元。鍊錶又分為單鏈表,雙向鍊錶,以及單迴圈鍊錶,多重鏈的迴圈鍊錶。本文先介紹單鏈表。典型的單鏈表結構...
資料結構之單鏈表
眾所周知,線性表是資料結構中的一種基本的資料結構。線性表的實現基本的有兩種 一種是順序儲存方式,另一種是鏈式儲存方式。順序儲存的線性表又叫順序表,實現時一般利用陣列等在記憶體中連續儲存的這個資料型別,所以順序表是一種隨機訪問的資料結構。順序表的優點是 可以快速訪問任一 位置的元素 並且無需為表示元素...