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).
typedef struct node* Lnode; struct node{ int val; Lnode next; }; typedef struct list* List; struct list{ Lnode head; int numNodes; };
List newList(void)
to dynamically allocate new list.
void append(List l, Lnode new)
that appends new node to an existing list.
void printList(List l)
that prints existing list.
void deleteNode(List l, int val)
that removes the first occurence of val in a list.
testList.c
and test the above functions.
How would implementation of the above functions and tests change if you use this representation.
void shuffle_merge(List l, List m)which merges two linked lists
l
and m
, taking nodes alternatively between the two lists.
void reverse(List l)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.
void swap(List l)which swaps every two nodes of the list
l
(e.g. 1->2->3->4->5
should become 2->1->4->3->5
. Last element is not swapped as it doesn't have a pair.)