知识大全 数据结构考研分类复习真题 第十章 答案[32]

Posted 结点

篇首语:人们常说,常识是两点之间最短的直线。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 数据结构考研分类复习真题 第十章 答案[32]相关的知识,希望对你有一定的参考价值。

     typedef struct node   ElemType data;  struct node *prior *next;  node *DLinkedList;  void  TwoWayBubbleSort(DLinkedList la)  //对存储在带头结点的双向链表la中的元素进行双向起泡排序   int exchange= ;  // 设标记  DLinkedList p temp tail;  head=la         //双向链表头 算法过程中是向下起泡的开始结点  tail=null;      //双向链表尾 算法过程中是向上起泡的开始结点  while (exchange)  p=head >next;    //p是工作指针 指向当前结点  exchange= ;      //假定本趟无交换  while (p >next!=tail)  // 向下(右)起泡 一趟有一最大元素沉底  if (p >data>p >next >data) //交换两结点指针 涉及 条链  temp=p >next; exchange= ;//有交换  p >next=temp >next;temp >next >prior=p //先将结点从链表上摘下  temp >next=p; p >prior >next=temp;     //将temp插到p结点前  temp >prior=p >prior; p >prior=temp;    else p=p >next; //无交换 指针后移  tail=p; //准备向上起泡  p=tail >prior;  while (exchange && p >prior!=head)  //向上(左)起泡 一趟有一最小元素冒出  if (p >data<p >prior >data)       //交换两结点指针 涉及 条链  temp=p >prior; exchange= ;     //有交换  p >prior=temp >prior;temp >prior >next=p //先将temp结点从链表上摘下  temp >prior=p; p >next >prior=temp;        //将temp插到p结点后(右)  temp >next=p >next; p >next=temp;    else p=p >prior;  //无交换 指针前移  head=p;             //准备向下起泡  // while (exchange)   //算法结束

cha138/Article/program/sjjg/201311/23173

相关参考