面试题:链表插入排序、冒泡排序
来源:互联网 发布:上交所网络投票平台 编辑:程序博客网 时间:2024/06/14 16:03
前些天去华赛面试,在经过详细的面试后,考官最后让我写一个链表排序的小程序,居然还写错了,惭愧回来痛定思痛,重新再实现了一遍
template<typename T>struct list_node{ struct list_node<T> *next; T value;};template<typename T>struct _list{ struct list_node<T> *head; int size;};
template<typename T>void SortLink(struct _list<T> * link) { struct list_node<T> *pHead,*pRear,*p,*tp; if (!link) return; for (pHead=link->head,pRear=0;pHead;pHead=pHead->next) { for (tp=pHead,p=pHead->next;p;tp=p,p=p->next) if (pHead->value>=p->value) tp->next=p->next,p->next=pHead,pHead=p,p=tp; if (!pRear) link->head=pHead; else pRear->next=pHead; pRear=pHead; }}
template<typename T>void InsertSort(struct _list<T> * list) { struct list_node<T> *pHead,*p,*tp,*m,*n; if (!list) return; pHead=list->head; p=pHead->next; while(!p) { tp=p; p=p->next; for(m=NULL;n=pHead;n!=NULL &&tp->next>n->value;m=n,n=n->next); if(!m) pHead=tp; else { m->next=tp; } tp->next=n; }}
template <typename T>void ReverseList(struct _list<T> * link){ struct list_node<T> *pHead,*pRear,*p,*tp; pHead=link->head; p=pHead->next; pHead->next=NULL; for(;p;p=tp) { tp=p->next; p->next=pHead; pHead=p; } link->head=pHead;};
- 面试题:链表插入排序、冒泡排序
- 面试题:冒泡排序,选择排序,插入排序,快速排序,归并排序,堆排序
- 面试题---冒泡排序
- 冒泡排序--面试题
- 面试题:插入排序
- JAVA面试题之冒泡排序,插入排序及选择排序
- 【面试题】冒泡排序&快速排序
- 快速排序与冒泡排序(面试题)
- 快速排序与冒泡排序(面试题)
- iOS 算法面试题(冒泡排序、选择排序、链表逆序)~demo
- 冒泡排序 插入排序
- 冒泡排序,插入排序
- 插入排序&&冒泡排序
- 冒泡排序,插入排序
- 冒泡排序、插入排序
- 冒泡排序,插入排序
- java面试题——冒泡排序
- (程序员面试题)冒泡排序
- 将excel 2007中的数据复制为图片
- ORA-16401 archivelog rejected by RFS 解决方法
- 【线程同步学习笔记】C#中的lock关键字
- WIN32_FIND_DATA
- php使用iconv进行从utf-8转为gb2312字符编码出错解决方案
- 面试题:链表插入排序、冒泡排序
- DB2 Rank-SQL查询 分组排序
- AIX笔记小节1
- iphone UIWEBVIEW JS回调交互
- starling-framework框架--GPU加速支持的2D Flash API!
- Oracle Data Guard Switchover 切换
- python获取linux的系统信息
- 今天碰到IE的一个问题, 两个IFRAME的问题
- wxFormbuileder中wxwidgets的布局控件(layout)的使用