資料結構 鍊錶及常見操作

2021-10-03 15:22:01 字數 1116 閱讀 7584

鍊錶最常見的結構有單鏈表,雙鏈表和迴圈鍊錶;

單鏈表只有乙個方向,結點只需要乙個額外的空間指向後面的結點,只能從前往後進行遍歷查詢資料;而雙向鍊錶可以向前和向後查詢資料,相對比較靈活,但是雙向鍊錶需要額外的兩個空間來儲存後繼結點和前驅結點的位址;儲存同樣多的資料,雙向鍊錶需要比單鏈表占用更多的空間。

1.單鏈錶類

static class node 

@override

public string tostring()

}

2.單鏈表反轉

private node reversal(node head)

return newhead;

}

3.單鏈表反轉(遞迴實現)

private node reversal2(node head)
4.鍊錶中環的檢測

private boolean checkcircle(node head)

return false;

}

5.兩個有序鍊錶合併(遞迴)

private node mergenode(node head1, node head2)  else 

return newnode;

}

6.刪除鍊錶倒數第 n 個結點

private node deletenode(node head, int n) 

while (first.next != null)

second.next = second.next.next;

return head;

}

資料結構 鍊錶操作

include include include include typedef int datatype typedef struct slistnode slistnode slistnode creatnewnode datatype data 申請空間存放新鍊錶 void slistnodep...

資料結構 鍊錶常見題目

include bool insert last list ls,data data tmp next node return true void display list ls printf n list createlist 建立鍊錶 ls head next null 空鍊錶 return l...

資料結構鍊錶 鍊錶的定義及基本操作

1,鍊錶的基本結構 typedef struct linklist linklist 2,鍊錶的初始化 linklist init list 3,新建鍊錶 void createlinklist linklist headnode,int data,int datanum headnode next...