错误蛋疼的反转 temp引用的地址已经被改变了所以不能实现反转
105 void reverse(void)
106 {
107 link node = head->next;
108 link temp;
109 temp = head;
110 head->next = head->pre;
111 head->pre = temp ->next;
112 while(node!=head){
113 temp = node;
114 node->next = node->pre;
115 node->pre = temp->next;
116 node = temp->next;
117 }
118 }
119
120
蛋疼的反转 105 void reverse(void) 106 { 107 link node = head->next; 108 link temp; 109 temp = head; 110 head->next = head->pre; 111 head->pre = temp ->next; 112 while(node!=head){ 113 temp = node->next; 114 node->next = node->pre; 115 node->pre = temp; 116 node = temp; 117 } 118 } 119 120 100 //通过pre照样能实现反序 101 for(; node->pre!=head; node=node->pre){ 102 printf("node->item=%d\n", node->pre->item); 103 } 104 1 /* circular.h */ 2 3 #ifndef CIRCULAR_H 4 #define CIRCULAR_H 5 6 typedef struct node *link; 7 struct node { 8 int item; 9 link pre, next; 10 }; 11 12 link make_node( int item); 13 void free_node(link p); 14 link search( int key); 15 void insert(link p); 16 void delete(link p); 17 void traverse(void (*visit)(link)); 18 void destroy(void); 19 void enqueue(link p); 20 link dequeue(void); 21 link get_head(void); 22 void list_node(void); 23 void reverse(void); 24 #endif 1 /* circular.c */ 2 #include <stdlib.h> 3 #include <stdio.h> 4 #include "circular.h" 5 6 struct node sentinel = {0, &sentinel, &sentinel}; 7 8 static link head = &sentinel; 9 10 link make_node( int item) 11 { 12 link p = malloc(sizeof *p); 13 p->item = item; 14 p->pre = p->next = NULL; 15 return p; 16 } 17 18 void insert(link p) 19 { 20 p->next = head->next; 21 head->next->pre = p; 22 head->next = p; 23 p->pre = head; 24 } 25 26 void delete(link p) 27 { 28 p->pre->next = p->next; 29 p->next->pre = p->pre; 30 } 31 32 33 34 void free_node(link p) 35 { 36 free(p); 37 } 38 39 link search( int key) 40 { 41 link p; 42 for(p=head->next; p!=head; p=p->next){ 43 if(p->item == key){ 44 return p; 45 } 46 } 47 return NULL; 48 } 49 50 void traverse(void (*visit)(link)) 51 { 52 link p; 53 for(p=head->next; p!=head; p=p->next){ 54 visit(p); 55 } 56 } 57 58 59 void destroy(void) 60 { 61 link q, p = head->next; 62 head->next = head; 63 head->pre = head; 64 while(p!=head){ 65 q = p; 66 p=p->next; 67 free_node(q); 68 } 69 } 70 71 void enqueue(link p) 72 { 73 insert(p); 74 } 75 76 link dequeue(void) 77 { 78 if(head->pre ==head){ 79 return NULL; 80 }else{ 81 link p = head->pre; 82 delete(p); 83 return p; 84 } 85 } 86 87 88 link get_head(void) 89 { 90 return head; 91 } 92 93 void list_node(void) 94 { 95 link node = head; 96 for(; node->next!=head; node=node->next){ 97 printf("node->item=%d\n", node->next->item); 98 } 99 }
相关推荐
通过java实现的双向链表,及反转功能,可能对面试有用哦
基于linkedList实现自己的双向链表反转。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。...
编写使用freelist 的带头、尾结点的双向链表类的定义,实现双向链表的基本操作。 2. 利用双向链表实现2个一元多项式的加法和乘法运算,运算结果得到的链表要求按照指数降序排列的多项式。 3. 最后提交完整的...
http://msdn.microsoft.com/en-us/library/95z04bas(v=VS.71).aspx 双向链表
数据结构的双链表算法:双链表基本运算插入前插入后,循环双链表的基本运算。用C++语言写的控制台程序。
双向链表
双向链表的操作问题 Time Limit: 1000MS Memory Limit: 10000KB Submissions: 111 Accepted: 41 Description 建立一个长度为n的带头结点的双向链表,使得该链表中的数据元素递增有序排列。(必须使用双向链表完成...
详细的介绍了Linux内核中使用的最频繁的双向链表
双向链表类定义及测试文件 对应于数据机构与算法分析(c++版)第三版或第二版 Clifford A.Shaffer 重庆大学使用教材
文档包括带表头单链表的实现,双链表的操作,双链表的冒泡排序,不带表头的单链表,双向链表、链表节点的排序
一种支持类模版和函数模版的C++双向链表,实现了各种排序算法(排序原则可定制),包含学生信息的使用示例(VC 6.0、VS2008).
实现双向链表的增删改查功能,dos窗口输入输出,可运行,有注释
操作系统c++编程实现安全型双向链表,线程的创建,利用线程对链表进行增删改操作,并检验结果是否正确
创建空的双向链表; 逐字符读取键盘输入的合法字符串,并依次插入到双向链表中。具体的,对于当前读取的字符, 构造其对应的结点。 利用头插法(或尾插法)将该结点按照键盘输入的顺序插入到双向链表中。 3、...
双向链表 - 数据结构与算法 C 双向链表 - 数据结构与算法 C 。。。。。。
原创手操,操作系统课设,线程安全的双向链表,VC6.0,无须配置,可运行
c++链表的反转,创建链表,插入链表,链表反转,可下载直接运行。
java实现双链表模拟集合练习题
用模板类实现了一个简单的双向链表domo。
通过建立双向链表,来实现双向查找,增加和删除的功能