-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedListlib.h
More file actions
31 lines (28 loc) · 843 Bytes
/
linkedListlib.h
File metadata and controls
31 lines (28 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdlib.h>
struct ListNode {
int val;
struct ListNode *next;
};
struct ListNode* createList(int* l1,int len){
struct ListNode* list1 = (struct ListNode*)calloc(1, sizeof(struct ListNode));
struct ListNode* head = (struct ListNode*)calloc(1, sizeof(struct ListNode));
if (len>0){
list1->val = l1[0];
// struct ListNode* temp = (struct ListNode*)calloc(1, sizeof(struct ListNode));
list1->next = NULL;
head = list1;
// list1 = list1->next;
for (int i = 1; i < len; i++){
list1->next = (struct ListNode*)calloc(1, sizeof(struct ListNode));
list1 = list1->next;
list1->val = l1[i];
list1->next = NULL;
}
list1 = head;
return list1;
}
else{
return NULL;
}
}