循环双链表数据结构!

问题相关代码,请勿粘贴截图

#include
#include

typedef struct Node{
int data;
struct Node* next;
struct Node* pre;
}Node;

Node* initList(){
Node* L = (Node*)malloc(sizeof(Node));
L ->data = 0;
L ->next = L;
L ->pre = L;
return L;
}

void headInsert(Node* L,int data){
Node* node = (Node*)malloc(sizeof(Node));
node ->data = data;
if(L ->data == 0){
node ->next = L ->next;
node ->pre = L;
L ->next = node;
L ->pre = node;
L ->data ++;
}
else{
node ->next = L ->next;
node ->pre = L;
L ->next ->pre = node;
L ->next = node;
L ->data ++;

}

}

void tailInsert(Node* L,int data){
Node* node = L;
while(node ->next !=L){
node = node ->next;
}
Node* n = (Node*)malloc(sizeof(Node));
n ->data = data;
n ->pre = node;
n ->next = L;
L ->pre = n;
node ->next = n;
L ->data ++;
}

void printList(Node* L){
Node* node = L ->next;
while(node !=L){
printf("%d ->",node ->data);
node = node ->next;
}
printf("NULL");
}

int main(){
Node* L = initList();
headInsert(L,1);
headInsert(L,2);
headInsert(L,3);
headInsert(L,4);
headInsert(L,5);
printList(L);
return 0;

}

运行结果及报错内容

error C2275: 'Node' : illegal use of this type as an expression
error C2065: 'n' : undeclared identifier
error C2223: left of '->data' must point to struct/union
error C2223: left of '->pre' must point to struct/union
error C2223: left of '->next' must point to struct/union
warning C4047: '=' : 'struct Node *' differs in levels of indirection from 'int '
warning C4047: '=' : 'struct Node *' differs in levels of indirection from 'int '

我想要达到的结果

本人初学者,看着别人的代码敲的但是报错了。希望有人帮我解决一下。

这段代码没有问题。

#include <stdio.h>
#include <stdlib.h>
typedef struct Node{
    int    data;
    struct Node* next;
    struct Node* pre;
}Node;

Node* initList(){
    Node* L = (Node*)malloc(sizeof(Node));
    L->data = 0;
    L->next = L;
    L->pre =  L;
    return L;
}

void headInsert(Node* L,int data){
    Node* node = (Node*)malloc(sizeof(Node));
    node->data = data;
    if(L->data == 0){
       node->next = L->next;
       node->pre = L;
       L->next = node;
       L->pre = node;
       L->data++;
    }
    else{
       node->next = L ->next;
       node->pre = L;
       L->next->pre = node;
       L->next = node;
       L->data++;
    }
}

void tailInsert(Node* L,int data){
    Node* node = L;
    while(node->next != L){
          node = node->next;
    }
    Node* n = (Node*)malloc(sizeof(Node));
    n->data = data;
    n->pre = node;
    n->next = L;
    L->pre = n;
    node->next = n;
    L->data ++;
}

void printList(Node* L){
    Node* node = L->next;
    while(node !=L){
         printf("%d ->",node->data);
         node = node->next;
    }
    printf("NULL\n");

    node = L->pre;
    while(node != L){
         printf("%d ->",node->data);
         node = node->pre;
    }
    printf("NULL\n");
}

int main(){
    Node* L = initList();
    headInsert(L,1);
    headInsert(L,2);
    headInsert(L,3);
    headInsert(L,4);
    headInsert(L,5);
    printList(L);
    return 0;
}

img