單鏈表實現氣泡排序

2021-08-20 19:49:46 字數 435 閱讀 3026

題目:

單鏈表實現氣泡排序

解題思路:

定義三個指標:pnode指向煉表頭,next指向第二個元素,tail指向的每輪結束的位置,開始為null。然後比較pnode和next的值,大就交換,當next為空時第一輪結束,記錄這個位置,下一趟排序只要next遇到這個位置就結束。

**實現:

void bubblenode(slistnode *pfirst)

while (tail!= pfirst->pnext) //當tail走到第二個數時迴圈結束

pnode = pnode->pnext;

next = next->pnext;

} if (flag == 0)

break;

tail = pnode; //尾指標前移

}}

單鏈表氣泡排序

一.題目 如題.二.package week 4 單鏈表氣泡排序 author dingding date 2017 7 3 12 25 public class sortlink solution,氣泡排序,直接交換兩個值,關鍵在於迴圈條件 private static node sort nod...

單鏈表 氣泡排序

main.c bubblesortlinkedlist headnode created by chenyufeng on 16 3 1.對帶頭結點的單鏈表進行氣泡排序,並列印 include include include typedef int elemtype typedef struct n...

單鏈表氣泡排序

今天做鍊錶排序有個誤區,就是以為交換的時候要連next節點也交換,還要固定head節點,想了很久也沒做出來,但是後來看網上的提示,才知道只要交換節點內的資料就可以了,根本不用交換next節點 include include struct node struct node create list in...