1、雙端鍊錶
2、測試雙端鍊錶
3、雙向鍊錶
4、測試雙向鍊錶
1、雙端鍊錶
2、測試雙端鍊錶package com.cwq.ch05;
import com.cwq.ch04.node;
/**
* 雙端鍊錶,將資料串起來
* @author carpoor
* @date 2023年1月29日
*/public
class
myfirstlastlinkedlist
/** * 插入資料,向隊頭插入
*/public
void
insertfirst
(long value)
node.next = first;
first = node;
}/**
* 插入資料,向隊尾插入
*/public
void
insertlast
(long value)
else
last = node;
}/**
* 刪除資料,刪隊頭
*/public node deletefirst()
first = first.next;
return tmp;
}/**
* 展示資料
*/public
void
display()
system.out.
println()
;}/** * 查詢資料
*/public node find
(long value)
current = current.next;
}return current;
}/**
* 刪除資料
*/public node delete
(long value)
prev = current;
current = current.next;}if
(current == first)
else
return current;
}public
boolean
isempty()
}
3、雙向鍊錶package com.cwq.ch05;
/**
* @author carpoor
* @date 2023年1月30日
*/public
class
testfirstlastmylinkedlist
}}
4、測試雙向鍊錶package com.cwq.ch05;
/**
* 雙端鍊錶,將資料串起來
* @author carpoor
* @date 2023年1月29日
*/public
class
mydoublelinkedlist
/** * 插入資料,向隊頭插入
*/public
void
insertfirst
(long value)
else
node.next = first;
first = node;
}/**
* 插入資料,向隊尾插入
*/public
void
insertlast
(long value)
else
last = node;
}/**
* 刪除資料,刪隊頭
*/public node deletefirst()
else
first = first.next;
return tmp;
}/**
* 刪除資料,刪隊尾
*/public node deletelast()
else
last = last.prev;
return tmp;
}/**
* 展示資料
*/public
void
display()
system.out.
println()
;}/** * 查詢資料
*/public node find
(long value)
current = current.next;
}return current;
}/**
* 刪除資料
*/public node delete
(long value)
prev = current;
current = current.next;}if
(current == first)
else
return current;
}public
boolean
isempty()
}
package com.cwq.ch05;
/**
* @author carpoor
* @date 2023年1月31日
*/public
class
testmydoublelinkedlist
system.out.
println
("------------------------------------");
list.
insertfirst(50
);list.
insertfirst(40
);list.
insertfirst(30
);list.
insertlast(50
);list.
insertlast(40
);list.
insertlast(30
);list.
display()
;while
(!list.
isempty()
)}}
資料結構 雙端鍊錶和雙向鍊錶
雙端鍊錶 一 什麼是雙端鍊錶。鍊錶中儲存著對最後乙個鏈節點引用的鍊錶。二 從頭部進行插入 要對鍊錶進行判斷,如果為空則設定尾節點為新新增的節點。三 從尾部進行插入 如果鍊錶為空,則直接設定頭結點為新新增的節點,否則設定尾節點的後乙個節點為新新增節點。四 從頭部進行刪除 判斷頭結點是否為下乙個結點,如...
鍊錶 三 雙向鍊錶
前兩篇部落格中介紹的鏈式儲存結構中只有乙個指示直接後繼的指標域。因此,從單鏈表中的某個結點出發,之能向後遍歷每個結點,所尋找這個結點的直接前驅只能向用頭結點出。而若在每個結點的指標域中再加入乙個指向當前結點直接前驅的指標,就可以克服以上問題。雙向鍊錶,帶頭節點,頭的前驅為null,尾的後繼為null...
鍊錶 05 雙向鍊錶
main.cpp include include doublelinkedlist.h using namespace std int main 雙向鍊錶類 class doublelinkedlist void insert doublelinkednode doublelinkednode 新節...