-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.c
53 lines (42 loc) · 1020 Bytes
/
list.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "list.h"
void listInsertBeginning(struct ListNode **head, char* value){
struct ListNode *var,*temp;
var=(struct ListNode *)malloc(sizeof(struct ListNode));
var->data = (char*) malloc((sizeof(char)* strlen(value))+1 );
strcpy(var->data,value);
if(*head==NULL){
*head = malloc(sizeof(var));
(*head)->data = (char*) malloc((sizeof(char)* strlen(value))+1 );
*head=var;
strcpy((*head)->data,var->data);
(*head)->next=NULL;
}
else {
temp=var;
temp->next=*head;
(*head)=temp;
}
}
int delete_head(struct ListNode **head)
{
struct ListNode *temp;
temp=(*head);
if(temp->next==NULL)
{
free(temp);
(*head)=NULL;
return 0;
}
(*head)=temp->next;
free(temp);
return 0;
}
int is_empty(struct ListNode *head){
if((head==NULL)||(head->next ==NULL))
return 1;
else
return 0;
}