-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlists.c
44 lines (35 loc) · 876 Bytes
/
lists.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
/* Library to manipulate linked-lists */
#include "lists.h"
void add_item (struct node **ptr, long double data)
{
struct node *new_item = malloc(sizeof *new_item);
new_item->value = data;
new_item->next = *ptr;
new_item->op = '?';
*ptr = new_item;
}
void delNextNode (struct node *head)
{
struct node *tmp = head->next;
head->op = head->next->op;
head->next = head->next->next;
free(tmp);
}
/* Function to reverse the linked list */
void reverse(struct node** head_ref)
{
struct node* prev = NULL;
struct node* current = *head_ref;
struct node* next = NULL;
while (current != NULL)
{
/* Store next */
next = current->next;
/* Reverse current node's pointer */
current->next = prev;
/* Move pointers one position ahead */
prev = current;
current = next;
}
*head_ref = prev;
}