-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_reverse.c
More file actions
37 lines (33 loc) · 952 Bytes
/
Copy pathlist_reverse.c
File metadata and controls
37 lines (33 loc) · 952 Bytes
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
/*
* This is the file in which you'll write a function to reverse a linked list.
* Make sure to add your name and @oregonstate.edu email address below:
*
* Name: Minh Nguyen
* Email: nguyemin@oregonstate.edu
*/
#include <stdio.h>
#include "list_reverse.h"
/*
* In this function, you will be passed the head of a singly-linked list, and
* you should reverse the linked list and return the new head. The reversal
* must be done in place, and you may not allocate any new memory in this
* function.
*
* Params:
* head - the head of a singly-linked list to be reversed
*
* Return:
* Should return the new head of the reversed list. If head is NULL, this
* function should return NULL.
*/
struct link* list_reverse(struct link* head) {
struct link* prev = NULL;
while(head != NULL){
struct link* next;
next = head->next;
head->next = prev;
prev = head;
head = next;
}
return prev;
}