public
class
_04linearlist02
//初始化指標域和資料域
private
node
(t obj,node
n)//得到當前節點的資料域
public t getdata()
//得到當前節點的指標域
public node
getnext()
}//鍊錶的長度
private
int length;
//鍊錶的虛擬頭節點
private node
head;
//單鏈表初始化
public
_04linearlist02()
//鍊錶的長度
public
intsize()
//線性表是否為空
public
boolean
isempty()
//返回鍊錶的頭節點
public node
gethead()
//單鏈表的插入
public
boolean
add(t obj,
int pos)
int num=1;
//p指向待刪除節點的前乙個節點
node
p=head;
while
(numnode
s=new
node
(obj, null)
; s.next=p.next;
p.next=s;
length++
;return
true;}
//單鏈表的刪除
public node
delete
(int pos)
if(pos<
1||pos>length)
node
p=head;
int num=1;
while
(numnode
res=p.next;
p.next=p.next.next;
length--
;return res;
}//單鏈表的查詢
public
intfind
(t obj)
node
p=head.next;
int num=1;
while
(p!=null)
else
}return-1
;}//獲取單鏈表第pos個節點的值
public t value
(int pos)
if(pos<
1||pos>length)
int num=1;
node
p=head.next;
while
(numreturn p.data;
}//更新單鏈表第pos個節點的值
public
boolean
modify
(t obj,
int pos)
if(pos<
1||pos>length)
int num=1;
node
p=head.next;
while
(nump.data=obj;
return
true;}
//遍歷單鏈表
public
void
iterator()
system.out.
println()
;}//清空單鏈表
public
void
clear()
public
static
void
main
(string[
] args)
}
線性表的鏈式表示
上篇文章是線性表的順序表示,本篇便是線性表的鏈式表示。主函式的步驟包括,輸入線性表資料,對鍊錶的刪除,插入。利用指標進行對鍊錶的訪問。同時為了增加程式可讀性,將結構體定義為lnode,linklist。include 線性表的鏈式表示 using namespace std typedef stru...
鏈式線性表
2013 03 23 00 14 39 上學期的時候就大致看了資料結構與演算法分析的了,但感覺收穫比較少,總結原因是程式設計實踐少了,所以今年趁著老師上課,就多進行一些 的實踐,也準備拿一些acm的題目來練練。中午的時候就將鏈式表的 打了一遍,現在貼上來分享。為了節省時間,我的注釋也相對較少,有不懂...
鏈式線性表和順序線性表
在這裡插入 片 線性表的儲存結構 typedef struct seqlist typedef struct seqlist 順序表基本操作 初始化順序表在這裡插入 片 intseqlist init seqlist list,int size 插入資料元素在這裡插入 片 intseqlist in...