shilicqupt

导航

 

2011年12月1日

摘要: 从CSDN看到几道有趣的关于链表操作的面试题,借此分析,最重要的是明白链表的操作方法问题1:输入一个单向链表,输出该链表中倒数第k个结点一个单向链表无法像数组一样可以直接索引,那么要找到链表的倒数第K个节点该怎么操作呢,其实思路非常简单,我们只需要设置两个指针p1,p2,首先p1和p2都指向链表的头部head,然后p2向前走k步,这样p1和p2之间就间隔k个节点,最后p1和p2同时向前移动,直至p2走到链表末尾,然后返回p1就是我们要找的链表的倒数K个节点。下面是关于这个问题具体的代码片段struct ListNode{ char data; ListNode *next;};Li... 阅读全文
posted @ 2011-12-01 14:57 shilicqupt 阅读(218) 评论(0) 推荐(0)
 

2011年11月29日

摘要: 本文主要介绍了优先队列完整的实现过程,主要实现的形式是使用二叉堆,使操作能快速被执行的性质是堆序性,最小元在根上,每个节点父亲的关键字小于自身节点关键字的值下面是关于优先队列实现定义的头文件binheap.h 1 typedef int ElementType; 2 #ifndef _BinHeap_H 3 #define _BinHeap_H 4 struct HeapStruct; //优先队列的结构体 5 typedef struct HeapStruct * PriorityQueue; 6 PriorityQueue Initialize(int MaxElement); //初始. 阅读全文
posted @ 2011-11-29 15:24 shilicqupt 阅读(318) 评论(0) 推荐(0)
 

2011年11月10日

摘要: #define leftchild(i) (2*(i))void perdown(int array[], int I, int length){ //下滤过程 int tmp, child; for(tmp=array[i]; leftchild(i)<length; i=child){ child = leftchild(i); if (child != length-1 && array[child]<array[child]+1) //判断child是否超过长度 child++; if (tmp<ar... 阅读全文
posted @ 2011-11-10 09:56 shilicqupt 阅读(143) 评论(0) 推荐(0)
 

2011年11月9日

摘要: shell sort version1void shell_sort(int array, int length){ int I, j, increment; int tmp; for (increment = length/2; increment>0; increment/=2) //控制两个被比较元素间的距离 for(i=increment; i<length; i++) //元素间的移位 for(j=I; j>0; j-=increment){ //用于比较相距increment个位置的元素 tmp ... 阅读全文
posted @ 2011-11-09 10:46 shilicqupt 阅读(103) 评论(0) 推荐(0)
 

2011年11月2日

摘要: 1 # Implements the Array ADT using array capabilities of the ctypes module.2 import ctypes34 class Array :5 # Creates an array with size elements.6 def __init__( self, size ):7 assert size > 0, "Array size must be > 0"8 self._size = size9 # Create the array structure usin... 阅读全文
posted @ 2011-11-02 17:30 shilicqupt 阅读(252) 评论(0) 推荐(0)
 
摘要: 分享一个用来判别是否是对称日的程序原理非常简单首先通过四位数反转得到求得八位数在进行验证后四位是否为有效的日期最后打印存在的日期就可以得到了所谓的对称数了 1 #include <stdio.h> 2 3 #define MIN_YEAR 1000 4 #define MAX_YEAR 9999 5 6 #define LEAPYEAR(x) ( (x%4==0&&x%100!=0||x%400==0)?1:0 ) 7 8 typedef enum { 9 USERFALSE = 0, 10 USERTRUE = 1 11 } USERBOOL; 12 ... 阅读全文
posted @ 2011-11-02 16:23 shilicqupt 阅读(239) 评论(0) 推荐(0)