-
Notifications
You must be signed in to change notification settings - Fork 0
/
List.c
54 lines (36 loc) · 894 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
// Name: Shatil Rahman
// ID: 260606042
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
#define TRUE 1
#define FALSE 0
static struct NODE *head;
void newList(){
head = NULL;
}
int addNode(int value){
struct NODE *temp;
temp = (struct NODE *)malloc(sizeof(struct NODE));
if(temp == NULL) return FALSE; // checking for failed allocation
if(head == NULL){ //if this is the first node in the list to be added
head = temp;
head->data = value;
return TRUE;
}
else{
temp->data = head->data; // stores the current head's info in the temp node structure
temp->next = head->next;
head->data = value; // sets the head to have the new value, and points to the previous head
head->next = temp;
return TRUE;
}
}
void prettyPrint(){
struct NODE *temp = head;
while(temp!= NULL){
printf("%d,", temp->data);
temp = temp->next;
}
printf("\n");
}