Yêu cầu thg 2 24, 2019 8:18 CH 112 0 0
  • 112 0 0
0

Lam sao de minh reverse linked list ?

Chia sẻ
  • 112 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
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí