資料結構 單鏈表 新增 不按順序和按順序

2021-10-04 14:44:00 字數 2233 閱讀 4429

2.1在新增英雄時,直接新增到鍊錶的尾部

思路分析:

}//定義singlelinklist管理我們的英雄

class

singlelinkedlist

//如果沒有找到最後,將temp後移

temp= temp.next;

}//退出white迴圈時,temp就指向了鍊錶的最後

temp.next = heronode;

}//顯示鍊錶

public

void

list()

//因為頭節點不能動,因襲需要乙個輔助變數來遍歷

heronode temp = head.next;

while

(true

)//輸出節點的資訊

system.out.

println

(temp)

;//將temp後移

2.2 在新增英雄時,根據排名將英雄新增到指定的位置

}//定義singlelinklist管理我們的英雄

class

singlelinkedlist

//如果沒有找到最後,將temp後移

temp= temp.next;

}//退出white迴圈時,temp就指向了鍊錶的最後

temp.next = heronode;

}//根據排名將英雄插入到指定的位置

//如果有這個排名,新增失敗,給出提示

public

void

addbyorder

(heronode heronode)

>heronode.no位置找到了,就在temp和temp.next之間插入

if(temp.next.no>heronode.no)

else

if(temp.next.no == heronode.no)

//後移

temp = temp.next;

}//退出迴圈後,先判斷flag的值

if(flag)

else

}//顯示鍊錶

public

void

list()

//因為頭節點不能動,因襲需要乙個輔助變數來遍歷

heronode temp = head.next;

while

(true

)//輸出節點的資訊

system.out.

println

(temp)

;//將temp後移

資料結構 順序表和單鏈表

typedef struct sqlist sqlist,psqlist bool isfull psqlist psq bool isempty psqlist psq void initsqlist psqlist psq 初始化 bool insert psqlist psq,int pos,...

資料結構 順序表和單鏈表c

include using namespace std constexpr auto maxsize 100 constexpr auto error 0 constexpr auto ok 1 typedef int elemtype 順序表的儲存結構 typedef struct sqlist ...

單鏈表的按位置插入和刪除

要想將結點s插入到ai與ai 1之間,不需要移動資料元素,只需要在ai與ai 1之間插入乙個新的結點,也就是我們要插入的結點s。關鍵就是要修改結點p的指標域,使得結點s稱為其後繼。把結點p的後繼作為結點s的後繼 2.p next s 把結點s作為結點p的後繼 注意這兩個語句的順序不能調換不能調換不能...