⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 revsindoulist.txt

📁 It is an ebook about data structures,mainly linked list
💻 TXT
字号:
How do you reverse a singly linked list? How do you reverse a doubly linked list? Write a C program to do the same. 

Discuss it!          


              

                     /* SINGLY LINKED LIST */ 

#include <stdio.h> 
#include <stdlib.h> 

struct linkedList{ 
    int element; 
    struct linkedList *next; 
}; 

typedef struct linkedList* List; 

List reverseList(List L) 
{ 
    List tmp, previous=NULL; 

    while(L){ 
        tmp = L->next; 
        L->next = previous; 
        previous = L; 
        L = tmp; 
    } 
    L = previous; 
    return L; 
     
} 

List recursiveReverse(List L) 
{ 
    List first, rest; 
    if(!L) 
        return NULL; 
    first = L; 
    rest = L->next; 
    if(!rest) 
        return NULL; 
    rest = recursiveReverse(rest); 
    first->next->next = first; 
    first->next = NULL; 
    L=rest; 

    return L; 
} 


 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -