-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.c
65 lines (62 loc) · 1.27 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
#include<stdlib.h>
#include "list.h"
void add_to_list(void *alloc_ptr)
{
struct node *ptr,*temp;
int item;
ptr = (struct node*)malloc(sizeof(struct node));
if(ptr == NULL)
{
printf("\nOVERFLOW");
}
else
{
ptr->ptr = alloc_ptr;
if(head == NULL)
{
ptr -> next = NULL;
head = ptr;
printf("\nNode inserted");
}
else
{
temp = head;
while (temp -> next != NULL)
{
temp = temp -> next;
}
temp->next = ptr;
ptr->next = NULL;
printf("\nNode inserted");
}
}
}
void remove_from_list(void *alloc_ptr)
{
struct node *ptr,*temp;
temp = head;
while (temp -> next != NULL)
{
if(temp->ptr == alloc_ptr)
{
temp->ptr == NULL;
printf("\nRemoved from the list\n");
}
temp = temp -> next;
}
}
void print_unfreed_ptrs()
{
struct node *ptr,*temp;
temp = head;
printf("printing unfreed\n");
while (temp -> next != NULL)
{
if(temp->ptr != NULL)
{
printf("%u is not freed\n",temp->ptr);
}
temp = temp -> next;
}
}