?? revsindoulist.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 + -