随笔分类 -  数据结构学习

数据结构复习笔记
摘要:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should ru... 阅读全文
posted @ 2014-06-17 23:11 Double_win 阅读(251) 评论(0) 推荐(0)
摘要:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After re... 阅读全文
posted @ 2014-06-17 14:58 Double_win 阅读(207) 评论(0) 推荐(0)
摘要:Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below 阅读全文
posted @ 2014-06-01 17:50 Double_win 阅读(459) 评论(0) 推荐(0)
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single 阅读全文
posted @ 2014-06-01 15:10 Double_win 阅读(194) 评论(0) 推荐(0)
摘要:题目描述: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the tot 阅读全文
posted @ 2014-05-22 16:53 Double_win 阅读(238) 评论(0) 推荐(0)
摘要:Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return 转载请注明出处: http://www.cnblogs.com/double-win/ 谢谢! 阅读全文
posted @ 2014-05-05 15:39 Double_win 阅读(176) 评论(0) 推荐(0)
摘要:n=412341213145111615610987n=512345161718196152425207142322218131211109简单的根据规律累加数字即可,注意几个边界条件的控制(向右 ,向下, 向左,向上的处理顺序)如果把(向右 ,向下, 向左,向上的处理顺序)作为一次处理逻辑,那么一共进行 n/2次循环即可。 1 #include 2 #include 3 using namespace std; 4 5 int a[100][100]={0}; 6 7 void fun(int n) 8 { 9 10 int c =1,i,j;11 fo... 阅读全文
posted @ 2014-04-02 22:29 Double_win 阅读(216) 评论(0) 推荐(0)
摘要:题目出自面试宝典8.3.2题目描述: 输入n,求一个n*n的矩阵,规定矩阵沿45度线递增,形成一个zigzag数组(JPEG编码里去像素数据的排列顺序),请问如何用C++实现?例如: n=20123n=3015246378n=50156142471315381216219111720221018192324分析每个矩阵中上三角矩阵,可以看到上三角矩阵的元素都满足:s= i+j;a[i][j] = s*(s+1)/2 +( (s%2==0)?i:j);此外,下三角的矩阵的每个元素满足 a[i][j] + a[n-1-i][n-1-j] = N-1;根据上面的分析,可以得到如下的程序:#inclu 阅读全文
posted @ 2014-04-02 21:40 Double_win 阅读(498) 评论(0) 推荐(0)
摘要:题目出处:HDU OJ 1496 http://acm.hdu.edu.cn/showproblem.php?pid=1496为了练习Hash,特定采用了杭电自带的分类列表http://acm.hdu.edu.cn/problemclass.php?id=64本题采用暴搜貌似也能AC,在这里就不再给出了.ps: 偏移量设置: a x1^2 + b x2^2 的取值范围 [-1000000,1000000]; 因此偏移量选择1000000即可 累积计数,可能出现多组数对的结果相同第21行 b1[t1 + OFFSET]++; 需要累加,而不是 b1[t1 + OFFSET] =1;代码... 阅读全文
posted @ 2014-03-25 16:24 Double_win 阅读(270) 评论(0) 推荐(0)
摘要:查找和排序是计算机应用中较为基础同时也很重要的两个组成成分。特别是当今网络如此盛行,Internet上充斥着各种各样的数据,图片,文本,音视频等,用户如何搜寻自己想要的数据,服务者如何及时有效的将用户的需求返回,都需要这些基础算法的帮助。在本人复习数据结构的时候,特意结合网上各位大牛的神贴,以及自己... 阅读全文
posted @ 2014-03-13 14:50 Double_win 阅读(307) 评论(0) 推荐(0)
摘要:(定义部分摘自清华大学出版社《数据结构(C语言版)》)1. 树的定义和基本术语 树(Tree)是具有n(n>=0)个节点的有限集合。在任意一颗非空树中:(1)有且仅有一个特定的节点称为“根”(root);(2) 当n>1时,其余节点又可以分为m个互不相交的有限集合T1,T2,...,Tm。这些集合,称为子树。m为与root直接相连的节点数目。 树的节点包含一个数据元素及若干指向其子树的分支。 结点拥有的子树数目称为结点的度(degree)。 出度为0的节点称为叶子(Leaf)或者终端结点。 度不为零的结点称之为分支节点。 一棵树的度是树内各结点的度的最大值。 一棵树的深度(dept 阅读全文
posted @ 2014-03-10 16:21 Double_win 阅读(448) 评论(0) 推荐(0)
摘要:根据清华大学出版社《数据结构(C语言版)》第三章所述,栈是限定仅在表尾进行插入或删除操作的线性表(其本质还是一个线性表)。其特性是数据入口和出口都是同一个,因此遵循“先入后出”的特性。既然是一个线性表,而且入口和出口相同,那么该结构需要有以下的数据属性:1. 栈底指针(struct Stack*ba... 阅读全文
posted @ 2014-03-10 11:37 Double_win 阅读(1538) 评论(0) 推荐(0)