Asked Feb 24th, 2019 8:18 p.m. 99 0 0
  • 99 0 0
0

Lam sao de minh reverse linked list ?

Share
  • 99 0 0
typedef struct list
{ 
    int item; 
    struct list* next;
}list;

struct * head = NULL;
struct list *head = NULL;

void reverse_list(list **l) {
    
}

Minh can phai reverse linked list dua tren mau code nay. Neu minh lam cach thong thuong thi no se nhu the nay

    void reverse_list(list **l) {
    list *current, *previous, *next;
        previous = NULL;
        current = head;
        while (current != NULL) {
            next = current->next;	// point to the next node
            current->next = previous; // reverse the direction
            previous = current;		// assign value to previous node as the list increments
            current = next;			// assign the value to current node as the list increments
        }
        head = previous; // assign the head node value at the end of the loop
    }

Con cach xai nhu the nay minh van chua hieu lam. void reverse_list(list **l)

Viblo
Let's register a Viblo Account to get more interesting posts.