將帶頭結點的單鏈表分解成兩個單鏈表,使其中一個含奇數號元素另一個含偶數號元素,並保持相對順序不變
阿新 • • 發佈: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 resolve10(node *h, node *bh) { node *p = h->next; node *hh=NULL; hh->next = h; bh->next = p; while (p&&p->next) { h->next = p->next; p->next = h->next->next; p = p->next; h = h->next; } if (h->next != NULL) h->next = NULL; h = hh; }