Skip to content

Commit b8a2116

Browse files
committed
base code set
1 parent 36d07c0 commit b8a2116

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

c/LinkedList/doubly/list.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
// Node structure
5+
typedef struct Node {
6+
int data;
7+
struct Node* next;
8+
struct Node* prev;
9+
} Node;
10+
11+
// Doubly Linked List structure
12+
typedef struct DoublyLinkedList {
13+
Node* head;
14+
Node* tail;
15+
} DoublyLinkedList;
16+
17+
// Function to create a new node
18+
Node* createNode(int data) {
19+
Node* newNode = (Node*)malloc(sizeof(Node));
20+
newNode->data = data;
21+
newNode->next = NULL;
22+
newNode->prev = NULL;
23+
return newNode;
24+
}
25+
26+
// Function to initialize an empty list
27+
DoublyLinkedList* createList() {
28+
DoublyLinkedList* list = (DoublyLinkedList*)malloc(sizeof(DoublyLinkedList));
29+
list->head = NULL;
30+
list->tail = NULL;
31+
return list;
32+
}

0 commit comments

Comments
 (0)