Saved Bookmarks
| 1. |
Give an O(n) time non-recursive procedure that reverses a singly linked list of n nodes. The procedure should not use more than constant storage beyond that needed for the list itself. |
|
Answer» The O (n) time non-recursive procedure that reverses a singly linked list of n nodes is as follows. reverse (struct node **st) { struct node *p, *q, *r; p = *st; q = NULL; while (p != NULL) { r =q; q = p; p = p → link; q → link = r; } *st = q; } |
|