Datastructure】的更多相关文章

使用Python实现直接插入排序.希尔排序.简单选择排序.冒泡排序.快速排序.归并排序.基数排序. #! /usr/bin/env python # DataStructure Sort # InsertSort def InsertSort(lst, end=None, beg=0, space=1): if end is None: end = len(lst) for i in range(beg, end, space): tmp = lst[i] j = i-space while j…
用Python模拟栈和队列主要是利用List,当然也可以使用collection的deque.以下内容为栈: #! /usr/bin/env python # DataStructure Stack class Stack: def __init__(self, data=None): if data is not None: self.stk = [data] self.top = 0 else: self.stk = [] self.top = -1 def __str__(self): r…
最近一直在学习Python和Perl这两门语言,两者共同点很多,也有不多.希望通过这样的模拟练习可以让自己更熟悉语言,虽然很多时候觉得这样用Python或者Perl并没有体现这两者的真正价值. #! /usr/bin/env python # DataStructure Linkedlist class Node: """ Member Variable: 1. next 2. data """ def __init__(self, data):…
Saving James Bond - Hard Version This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the cente…
数据结构习题集-4-2 集合的运用 1.题目: We have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer to another. Is it possible to send a file from any computer on the network to any othe…
数据结构练习 4-1 AVL 树 1. 题目: Input Specification: Each input file contains one test case. For each case, the first line contains a positive integer N (<=20) which is the total number of keys to be inserted. Then N distinct integer keys are given in the ne…
本篇博客实现了 1.冒泡排序 2.冒泡排序的一种优化(当某次冒泡没有进行交换时,退出循环) 3.选择排序 4.归并排序 5.快速排序. 主要是源码的实现,并将自己在敲的过程中所遇到的一些问题记录下来. 全局定义与相关声明: #include <iostream> #include <cstdio> #include <cstring> using namespace std; int num[100005]; //存储数组 void swap1(int i, int j…
1.前言 本文伪码和解释参考: http://blog.csdn.net/v_JULY_v/article/details/6105630 C实现的源码本文未贴出,请见: http://blog.csdn.net/v_july_v/article/details/6114226 July的博客对红黑树的分析很精彩,请见: http://blog.csdn.net/v_JULY_v/article/category/774945 本文对参考资料有所修订和补完(侵删). 2.正文 伪码中使用的符号:…
catalogue . 引论 . 数据结构的概念 . 逻辑结构实例 2.1 堆栈 2.2 队列 2.3 树形结构 二叉树 . 物理结构实例 3.1 链表 单向线性链表 单向循环链表 双向线性链表 双向循环链表 数组链表 链表数组 二维链表 3.2 顺序存储 . 算法 4.1 查找算法 4.2 排序算法 0. 引论…
11988 - Broken Keyboard (a.k.a. Beiju Text) 可以用deque来模拟. #include <iostream> #include <string> #include <string.h> #include <stdio.h> #include <queue> using namespace std; ; char ch[MAX]; int main() { while (scanf("%s&qu…
Check whether a given graph is Bipartite or not A Bipartite Graph is a graph whose vertices can be divided into two independent sets, U and V such that every edge (u, v) either connects a vertex from U to V or a vertex from V to U. In other words, fo…
Given a Directed Graph and two vertices in it, check whether there is a path from the first given vertex to second. For example, in the following graph, there is a path from vertex 1 to 3. As another example, there is no path from 3 to 0. We can eith…
#include<iostream> #include<cstdio> #include<cstring> #include<limits> #include<vector> using namespace std; ; struct edge{ int to, cost; edge(int t){ ; } }; void addEdge(vector<edge> &edgelist, vector<vector<…
#include<iostream> #include<cstdio> #include<cstring> #include<limits> #include<vector> using namespace std; struct BST{ int key; BST *lc, *rc; BST(){ ; lc = rc = NULL; } BST(int k){ this->key = k; lc = rc = NULL; } }; BST…
使用Python模拟二叉树的基本操作,感觉写起来很别扭.最近做编译的优化,觉得拓扑排序这种东西比较强多.近期刷ACM,发现STL不会用实在太伤了.决定花点儿时间学习一下STL.Boost其实也很强大.关于Python最近没什么时间搞了,忙着复试了.不过,挺喜欢这语言的.复试完继续大战PythonChallenge. #! /usr/bin/env python # DataStrucure Tree import sys class BTNode: def __init__(self, data…
[Description] A queue is a collection that implements the first-in-first-out protocal. This means that the only accessiable object in the collection in the first one that was inserted. The most common example of a queue is a waiting line. [Interface]…
Method 1: Add one list into the other list. For example, if list1is {22, 33, 44, 55} and  list2 is {66, 77, 88, 99},then append(list1, list2)will change list1to {22, 33, 44, 55, 44, 66, 77, 88, 99}. static void append(Node list1, Node list2) { if (li…
The Java Connections FrameWork is a group of class or method and interfacs in the java.util package. Its main purpose is to provide a unified framework for implementing common data structure. A collections is a object that contains other objects,whic…
Method 4: Gets the value of element number i For example, if list is {22, 33, 44, 55, 66, 77, 88, 99}, then get(list, 2) will return 44. Solution 1: static int get(Node list, int i) { if (i < 0) { throw new IllegalArgumentException(); } for (int j =…
Last night it took me about two hours to learn arrays. For the sake of less time, I did not put emphaises on the practice question, just now when reading the book, I found that some methods referred to arrays are so beneficial to us. So in here make…
01.list ''' list 특징 - 1차원 배열 구조 형식) 변수 = [값1, 값2] - 다양한 자료형 저장 가능 - index 사용=순서 존재 형식) 변수[n] - 값 수정(추가,수정,삭제,삽입) ''' # 1. 단일 list lst = [1,2,3,4,5] print(lst) # [1, 2, 3, 4, 5] lst = list(range(1,6)) print(lst) # [1, 2, 3, 4, 5] for i in lst : print(…
Bloom Filters Ref[1] 1. 简介 Bloom filter(布隆过滤器:有更好的或正确的翻译,告诉我) 是一个数据结构,该数据结构快速并且内存高效,它可以告诉你某个元素是否在集合中. 作为高效的代价,Bloom filter是存在概率的数据结构:它告诉我们某个元素一定不在集合中,或者可能在集合中. Bloom filter的基本数据结构是Bit Vector. 在Ref[1]中有简单形象的例子来说明Bloom Filter. 1.1 Hash Functions 在Bloom…
Arrayss work well for unordered sequences, and even for ordered squences if they don't change much. But if you want to maintain an ordered list that allows quick insertions and deletions, you should use a linked data structure. so inserting an elemen…
/** * Method 1: Delete the input element x  * and meanwhile keep the length of array after deleted n * @param a  the array * @param n  the length of array after deleted. * @param x  the element that need to be deleted. */ static void delete(int[] a,…
时间复杂度的计算 计算最坏情况下执行语句的次数(含有n) 去掉常数项, 只保留最高项, 去掉系数 最后的结果一般是1, logn, n, nlogn, n^2, 2^n, n!, n^n 时间复杂度所消耗的时间的顺序是: O(1) < O(logn) < O(n) < O(nlogn) < O(n^2) < O(n^3) <O(2^n) < O(n!) <O(n^n) 使用线性表实现多项式加法 使用顺序表, 下标表示幂数, 对应下标中内容为系数 使用链表,…
[Description] At ree is a nonlinear data structure that models a hierarchical organization. The characteristic eatures are that each element may have several successors (called its "children") and every element except one (called the "root&…
In an attempt to remove duplicate elements from list, I go to the lengths to take advantage of  methods in the java api. After investiagting the document of java api, the result is so satisfying that I speak hightly of wisdom of developer of java lan…
Statements: This blog was written by me, but most of content  is quoted from book[Data Structure with Java Hubbard] [Description] This simulationillustrates objectoriented programming(OOP). Java objects are instantiated to represent all the interacti…
In the Java collection framework, there are three similar methods, addAll(),retainAll() and removeAll().  addAll(), the retainAll(), and the removeAll()methods are equivalent to the set theoretic union,  intersection, and complement operators, respec…
使用过C++ <STD> 库的猿友们应该都觉得 C++中那些已经实现好了的数据类型封装使用让人很是舒服; 例如 vector 支持自动扩充数组,支持模板类,任何数据类型都可以 简单的管理,如果在C语言中,我们就 需要预先声明数组或者动态声明指针,最最重要的是,同样的事情我们有可能需要做很多遍,那么有没有什么 方式可以让C语言也可以实现类似C++中数据类型的功能呢? 答案当然是可以的,不仅可以实现自动管理数组,同时还支持代码膨胀,也就是支持自定义的数据类型 (无限嵌套哦): 笔者我就想编写这么一…