1. 程式人生 > >設計一個遞迴演算法刪除不帶頭節點單鏈表L中所有值為x的節點

設計一個遞迴演算法刪除不帶頭節點單鏈表L中所有值為x的節點

#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 recursiondel1(node *h, type x)
{
    node *p;
    if (h == NULL)
        return;
    if (h->data == x)
    {
        p = h;
        h = h->next;
        free(p);
        recursiondel1(h, x);
    }
    else
        recursiondel1(h->next, x);

}