刪除帶頭節點的單鏈表的最小值節點的高效演算法
阿新 • • 發佈:2018-12-10
#include "stdafx.h" #include<stdio.h> #include<malloc.h> #include<stdlib.h> typedef int type; typedef struct lnode //定義連結串列結點的資料結構 { int data; struct lnode *next; }Lnode; typedef Lnode node; typedef struct dnode//定義雙鏈表結點的資料結構 { int data; struct dnode *lnext; struct dnode *rnext; }Dnode;
void delminest4(node *h) { node *p, *q, *min; if (h->next == NULL) return; p = h; min = q = h->next; while (q->next != NULL) { if (q->next->data<min->data) { p = q; min = q->next; } q = q->next; } p->next = min->next; free(min); }