List.c
and use the following struct definition for your implementation:
typedef struct node* Lnode; struct node{ int val; Lnode next; };
Lnode newNode(int value)
to dynamically allocate new node and initialise it.
Lnode prepend(Lnode head, Lnode new)
that prepends new node to an existing list.
Lnode append(Lnode head, Lnode new)
that appends new node to an existing list.
void printList(Lnode head)
that prints existing list.
Lnode deleteNode(Lnode head, int val)
that removes the first occurence of val in a list.
testList.c
and test the above functions.
typedef struct node* Lnode; struct node{ int val; Lnode next; }; typedef struct list* List; struct list{ Lnode head; int numNodes; };How would implementation of the above functions and tests change if you use this representation.
Lnode concat( Lnode L, Lnode M )which concatenates two linked lists
L
and M
into a single list containing
all the nodes of L (in their original order)
followed by all the nodes of M (in their original order)
and returns a pointer to the head of the new list.
Lnode
structure
write a function
Lnode reverse( Lnode head )which reverses the nodes of a linked list, so that the ordering of the nodes becomes exactly the opposite of what it was before. The function should return a pointer to the head of the new list.
valgrind
and gdb
. Show how you would use these tools to check for memory leaks and debug segmentation faults. (For gdb show at least commands like where, info locals, print
and how to set a breakpoint).
PS: Usually, to include debug symbols you will compile your program with -g
flag, however on cse machine you will need to use -gdwarf-2
flag to produce debugging symbols.