摘要: 好像还是有问题,在研究下! 阅读全文
posted @ 2010-11-15 22:43 hailong 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 逆转单向链表是一个很基础很常见的问题,可惜在我最近面试的几个面试者中还是发现有的人写不好这个程序或者写的有问题.请看下面的实现,这也是大多数人聪明的人会想到的实现方法typedef struct Node{ int data; struct Node *next;}node;elementT *reverse(Node *p,Node *head){ if((!p)|| !(p->next)... 阅读全文
posted @ 2010-11-14 21:09 hailong 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 基本原理仍然easy,直接上代码:运行结果: 阅读全文
posted @ 2010-11-14 16:45 hailong 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 就是酱紫: 阅读全文
posted @ 2010-11-13 20:35 hailong 阅读(98) 评论(0) 推荐(0) 编辑
摘要: 栈的特点是后进先出,队列的特点是先进先出。所以,用两个栈s1和s2模拟一个队列时,s1作输入栈,逐个元素压栈,以此模拟队列元素的入队。当需要出队时,将栈s1退栈并逐个压入栈s2中,s1中最先入栈的元素,在s2中处于栈顶。s2退栈,相当于队列的出队,实现了先进先出。显然,只有栈s2为空且s1也为空,才算是队列空。[算法讨论]算法中假定栈s1和栈s2容量相同。出队从栈s2出,当s2为空时,若s1不空,... 阅读全文
posted @ 2010-11-12 22:23 hailong 阅读(3110) 评论(0) 推荐(1) 编辑
摘要: 看起来比较麻烦,不过我写的实现比较简单,估计还有很多问题,哪位看出来了,帮忙指出来啊!3Q! 阅读全文
posted @ 2010-11-12 21:42 hailong 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 暂时先记下,慢慢研究!代码 阅读全文
posted @ 2010-11-12 09:22 hailong 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 代码奉上,原理灰常简单: 阅读全文
posted @ 2010-11-11 22:43 hailong 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 原理比较简单,不在叙述。代码如下:实现了一些基本操作。 阅读全文
posted @ 2010-11-11 21:10 hailong 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 网站给的步骤是:1,学会懒惰2,精通Android体系架构、MVC、常见的设计模式、控制反转(IoC)3,编写可重用、可扩展、可维护、灵活性高的代码4,高效的编写高效的代码5,学会至少一门服务器端开发技术 阅读全文
posted @ 2010-11-10 16:50 hailong 阅读(235) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>using namespace std;void inline SWAP(int &a,int &b){ int temp = a; a = b; b = temp;}int paitition(int *a,int p,int r){ int i = p-1; int x = a[r-1]; for(int j = p; j <... 阅读全文
posted @ 2010-11-06 22:25 hailong 阅读(105) 评论(0) 推荐(1) 编辑
摘要: quicksort(A,p,r){if p < r; then q<- partition(A,p,r) quicksort(A,p,q-1) quicksort(A,p+1,r)}其中partition(A,p,r){x<-A[r]i<-p-1for j<-p to r-1 do if A[j]<= x then i++; exchange A[i]<-... 阅读全文
posted @ 2010-11-06 09:30 hailong 阅读(4363) 评论(0) 推荐(0) 编辑
摘要: 问题描述:请给出一个时间为O(nlgk)、用来将k个链表合并为一个链表的算法。此处n为所有输入链表中的元素总数。(提示:用一个最小堆来做k路合并)解答:(1)把k个链表的第一个元素放入数组A,利用数组A建立最小堆。时间复杂度是lg(K);(2)在返回A[1],在数组中寻找到之后,插入新链表;(3)然后移除A[1],heap_size-1,在把剩下的排成最小堆; (4)重复步骤(2)直至heap_s... 阅读全文
posted @ 2010-11-05 21:54 hailong 阅读(419) 评论(5) 推荐(0) 编辑
摘要: 因为优先级队列是一种用来维护由一组元素构成的集合S的数据结构,执行的操作包含:对于最大优先级队列:insert(S,x)把元素x插入S,仍然保持最大优先级队列maximum(S)取得最大关键字的值,也就是优先级最高的extract_max(S):去的最大关键字的值并删除,剔除优先级最高的increase_key(S,x,k):在第i的元素上换成K并保持S的性质,是此元素优先级提高对于最小优先级队列... 阅读全文
posted @ 2010-11-05 17:08 hailong 阅读(1203) 评论(0) 推荐(0) 编辑
摘要: 根据书上的伪代码实现的最大堆,以及在最大堆基础上实现的优先级队列: 阅读全文
posted @ 2010-11-05 15:04 hailong 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 按照《算法导论》上的伪代码实现了,刚开始没注意index的问题,导致错误,看来对于伪代码实现C还是要注意下啊!!#include<iostream>#include <time.h> using namespace std;const int n=11;void print(int *a){ for(int i = 0; i < 11; ++i) cout <... 阅读全文
posted @ 2010-11-04 14:59 hailong 阅读(156) 评论(0) 推荐(0) 编辑
摘要: Bitwise operator in C/C++ 歡迎來到二進位的世界。電腦資料都是以二進位儲存,想當然程式語言的變數也都是以二進位儲存。在 C/C++ 當中有幾個位元運算子: << SHIFT LEFT 、 >> SHIFT RIGHT 、 & AND 、 | OR 、 ^ XOR 、 ~ NOT ,可以對變數進行位元運算。接下來要介紹位元運算的一些用途。 &l... 阅读全文
posted @ 2010-10-30 09:44 hailong 阅读(372) 评论(0) 推荐(0) 编辑
摘要: 输入a,n,k(1<=a,n<=1e9 1<=k<=10000 ,注意:有多组测试数据,请用EOF标志判断结束输入):2 32 52 30 5输出(a^n)%k的结果(a的n次方被k除的余数):14问题分析:因为存在若n为偶数:a^n=(a*a)^[n/2];若n为奇数:a^n=a*(a*a)^[n/2];所以原问题就可以进行简化了代码如下 阅读全文
posted @ 2010-10-28 20:25 hailong 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 雜湊表( hash table )。元素的索引值由特殊方法決定,是一種特殊的歸類。inthash(intn)//根據元素的數值來製造一個index{returnn*97%100;}voidhash_table(){intarray[5]={3,6,9,8,1};inttable[100];for(inti=0;i<5;i++){//替array[i]製造一個indexintindex=has... 阅读全文
posted @ 2010-10-28 15:24 hailong 阅读(91) 评论(0) 推荐(0) 编辑
摘要: C 语言数据类型: 基本类型、构造类型、指针类型、空类型.基本类型又包括: 整型、字符、浮点(单精度、双精度)、枚举.构造类型又包括: 数组、结构体、公用体.1. 显示整型(int)的最小、最大值:#include <stdio.h>#include <limits.h>int main(void){ int n1,n2; n1 = INT_MIN; n2 = INT_MA... 阅读全文
posted @ 2010-10-28 09:31 hailong 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 为什么写了个字符串的函数,两个差不多的函数差距怎么就这么大呢?第二个直接运行不出来,郁闷啊,谁能帮忙回答一下啊!!修改了一下,原来是在最后一个字符上出了问题char* substring(char *s,int first,int end) { char *t=new char[end-first+1]; int j=0,i=first; while(i<end) t[j++]=s[i++... 阅读全文
posted @ 2010-10-28 09:28 hailong 阅读(339) 评论(0) 推荐(0) 编辑
摘要: 简单功能模仿:stack:函数实现voidstack(){ int stcak[10]; int top=0;while(top<10) stack[top++]=top;while(top>0) cout<<stack[--top]<<" ";}queue:函数实现void queue(){ int queue[10];int front=0,rear=0;q... 阅读全文
posted @ 2010-10-28 07:18 hailong 阅读(232) 评论(0) 推荐(0) 编辑
摘要: Top-down 由粗略的架構開始分析,逐步具體化,追溯出問題的細目。以生物分類法為例,其分類的層次由上往下依序為界門綱目科屬種,由粗略到清晰,此即是 Top-down 。簡單來說,就是立下大綱後,再研究細節。Bottom-up 從基礎的條理開始綜合,逐步抽象化,建構起問題的綱要。以數學理論的推導過程為例,由簡單的基本假設,推論出高深的理論,此即是 Bottom-up 。簡單來說,就是確定細節後,... 阅读全文
posted @ 2010-10-27 22:08 hailong 阅读(151) 评论(0) 推荐(0) 编辑
摘要: Problem D: Above AverageIt is said that 90% of frosh expect to be above average in theirclass. You are to provide a reality check.The first line of standard input contains an integer C,the number of... 阅读全文
posted @ 2010-10-26 22:49 hailong 阅读(165) 评论(0) 推荐(0) 编辑
摘要: The ProblemMedian plays an important role in the world of statistics. By definition,it is a value which divides an array into two equal parts. In this problemyou are to determine the current median of... 阅读全文
posted @ 2010-10-26 22:10 hailong 阅读(511) 评论(0) 推荐(0) 编辑
摘要: A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. For instance,1 4 2 3is a jolly jumpe... 阅读全文
posted @ 2010-10-26 14:40 hailong 阅读(271) 评论(0) 推荐(0) 编辑
摘要: In this problem you are to generate a triangular wave form according to a specified pair of Amplitude and Frequency.Input and OutputThe input begins with a single positive integer on a line by itself ... 阅读全文
posted @ 2010-10-25 22:25 hailong 阅读(552) 评论(0) 推荐(0) 编辑
摘要: 合抱之木,生於毫末;九層之臺,起於累土;千里之行,始於足下。加總數字:無論電腦再怎麼強,還是得一個一個數字累加。複製字串無論電腦再怎麼強,還是得逐字複製。選擇排序法( Selection Sort )把第一小的數值找出來,放在第一個位置;再把第二小的數值找出來,放在第二個位置。一次找一個數字,如此下去就可把所有數值按照順序排好了印出直角三角形 阅读全文
posted @ 2010-10-25 20:26 hailong 阅读(92) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<string>#include<vector>#include<math.h>using namespace std;string sum(string a,string b){int n1=a.length(),n2=b.length();int n=n1>=n2?(n1+1):(n2+1... 阅读全文
posted @ 2010-10-25 15:37 hailong 阅读(175) 评论(0) 推荐(0) 编辑
摘要: max_heapify(a,n,i) largest=i; temp=-1; while(lagesta[largest]) then largest=l; if(ra[largest]) then largest=r; if(largest!=temp) then ... 阅读全文
posted @ 2010-10-24 21:35 hailong 阅读(164) 评论(0) 推荐(0) 编辑