双向链表

 

双向链表

11-27

======================================.hrnrn#include rn#include rnrntypedef int status;rntypedef struct DouList rn struct DouList *front;rn struct DouList *next; rn int item;rnDouList;rnrn/*功能: 将 e 插入到 链表指定位置的前部(双链表)rn *输入: DouList e, DouList listrn *返回: 0 成功 1失败rn *思路: rn * 1. 如果是首节点 e->front = cur->front; e->next = cur; e->last = cur->last;rn cur->front = e;rn * 2. 如果是中节点 e->front = cur->front; e->next = cur; e->last = cur->last;rn e->front->next = e;rn cur->front = e; rn */rnstatus insert( DouList *e, DouList *cur )rnrn if( NULL == cur->front )rn rn e->front = NULL;rn e->next = cur;rn cur->front = e;rn return 0;rn rn else if( NULL != cur->front )rn rn e->front = cur->front;rn e->next = cur;rn e->front->next = e;rn cur->front = e;rn return 0;rn rn else rn return -1;rnrnrn/*rn *功能: 将递增链表 转换为 1,3,5,4,2rn *输入: DouList list;rn *返回: 0 成功, 1 失败rn *思路: rn * 1.依次从头开始遍例链表,第一次碰到偶节点时,将其移动至表尾。rn * 2.从第二次开始,每次都将找到的偶节点移动到上次移动节点的前方。rn * 3.检查是否到达初始的尾部rn */rnstatus Lturn( DouList *L )rnrn DouList *InitList = L; //初始尾部rn DouList *CurList;rn DouList *temp = L;rnrn temp->next = L->front;rn CurList = temp->next;rn temp->next = temp;rnrn while( temp != L->front || temp != L->front->front )rn rn temp = temp->next->next;rn insert( temp, CurList );rn CurList = temp;rn temp = temp->next->next;rn rn rn if( temp == L->front || temp == L->front->front )rn return 0;rn elsern return 1;rnrn rnrn======================================.crnrn/*rn * 设以带头结点的双向循环链表表示的线性表L=(a1,a2,...an).试写一时间复杂度为O(n)的算法rn * 将L改造为L=(a1,a3,....,an,...,a4,a2).rn */rn#include "2.37.h"rnrnint main(void)rnrn int i;rn rn DouList *list = ( DouList * ) malloc( sizeof( DouList ) );rn list->front = NULL;rn list->next = NULL;rn list->item = 0;rnrn DouList *head;rn head = list;rnrn for( i=0; i<10; i++ )rn rn DouList *temp = ( DouList * ) malloc( sizeof( DouList ) );rn if( NULL == head->front )rn rn temp->front = list;rn temp->next = NULL;rn temp->item = i;rnrn list->front = temp;rn head->next = temp;rn head = head->next;rn rn elsern rn temp->front = head;rn temp->next = NULL;rn temp->item = i;rnrn list->front = temp;rn head->next = temp;rn head = head->next;rn rn rn rn Lturn( list );rn rn head = list;rn while( head->next != NULL )rn printf( "item = %d\n",head->item );rn system( "pause" );rn return 0;rnrnrn==========================================错误信息rn所有的错误信息 全部来自 head (DouList *head), 但是其它以相同方式声明并初始化的 标识符 都没事,只有它不行。。。rn想不出来是为什么。。。rnrn错误 1 16 error C2275: “DouList”: 将此类型用作表达式非法 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 2 16 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 3 17 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 5 22 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 6 22 error C2223: “->front”的左侧必须指向结构/联合 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 7 29 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 8 29 error C2223: “->next”的左侧必须指向结构/联合 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 9 30 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 10 30 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 11 30 error C2223: “->next”的左侧必须指向结构/联合 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 12 34 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 14 39 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 15 39 error C2223: “->next”的左侧必须指向结构/联合 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 16 40 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 17 40 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 18 40 error C2223: “->next”的左侧必须指向结构/联合 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 19 46 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 21 47 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 22 47 error C2223: “->next”的左侧必须指向结构/联合 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 23 48 error C2065: “head”: 未声明的标识符 f:\code\temp_project\chapter 2 list\2.37\2.37.crn错误 24 48 error C2223: “->item”的左侧必须指向结构/联合 f:\code\temp_project\chapter 2 list\2.37\2.37.crnrnrn

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试