
Data Structure
文章平均质量分 70
诗意de栖居
这个作者很懒,什么都没留下…
展开
-
DSOJ Kth Number(第k大的数)
题目链接#include //查找数组中第k小的元素#define MAX 100/*算法思想:模仿快排的做法,首先去数组中任何一个元素(不妨取第一个),将数组分为两部分,s[0,..p-1],和s[p+1,...n-1],其中左半部分的值都不大于s[p],右半部分的值都不小于s[p]此时如果p==k-1,则说明s[p]即为所要找的第k小的元素,返回s[p]否则,如果p>k-原创 2015-12-19 13:58:33 · 588 阅读 · 0 评论 -
DSOJ Multiplication of large integer(大数乘法)
题目链接#include //大整数相乘(输入为两个不超过200位的非负整数,无前导0,要求输出也无前导0)#include //算法思想:类似于笔算整数的乘法,分别用一个乘数的各位数乘以另一个乘数的各位数,再错位相加,//最后进行进位的处理即可求得最终结果。void compute(int *a, char *s1, char *s2) //大整数相乘{ int len原创 2015-12-19 13:57:35 · 633 阅读 · 0 评论 -
DSOJ Addition of Polynomial(多项式求和)
题目链接#include //多项式的加法#include //多项式本身可能不是最简的情况,即需要合并多项式幂指数相同的项typedef struct node{ int coef; //系数coefficient int expn; //指数exponent struct node *next;}Node;Node *insert(Node *head, Node原创 2015-12-19 13:55:08 · 632 阅读 · 0 评论 -
DSOJ Sliding Window
题目链接#include //Sliding Window#include/*算法思想:选择单调队列的数据结构对于求最小值而言,建立队列元素递增的单调队列,队首保存的即为最小值,在将数组元素入队的过程中,需要记录入队元素的index,用于求从a[i-k+1]....a[i]的最小值时判断队首元素是否还在宽度为k的窗口中入队过程:将队尾元素与将要入队的元素进行比较,将队尾元原创 2015-12-19 13:53:15 · 320 阅读 · 0 评论 -
LeetCode Sort List(链表排序)
题目链接struct ListNode *MergeSortList(struct ListNode *head1, struct ListNode *head2){ struct ListNode *p1, *p2, *p, *temp; p = (struct ListNode *)malloc(sizeof(struct ListNode)); temp = p; //暂存原创 2015-12-19 13:38:53 · 483 阅读 · 0 评论 -
LeetCode Merge Two Sorted Lists(合并两个有序链表)
题目链接struct ListNode *MergeSortList(struct ListNode *head1, struct ListNode *head2){ struct ListNode *p1, *p2, *p, *temp; p = (struct ListNode *)malloc(sizeof(struct ListNode)); temp = p; //暂存原创 2015-12-19 13:34:39 · 332 阅读 · 0 评论 -
LeetCode Merge Sorted Array(合并有序数组)
题目链接#include //Merge Sorted Array/*算法思想:利用插入排序的算法思想,依次遍历nums2中的每一个元素,并将其插入到有序的nums1中*/void merge(int* nums1, int m, int* nums2, int n) { int i, j, k; i = 0; j = 0; while (j < n) { whi原创 2015-12-19 13:32:23 · 365 阅读 · 0 评论 -
HackerRank Huffman Decoding(Huffman解码)
题目链接/* The structure of the node istypedef struct node{ int freq; char data; node * left; node * right; }node;*/void decode_huff(node * root,string s){ char str[50原创 2015-12-19 10:39:45 · 527 阅读 · 0 评论 -
HackerRank Reverse a linked list(逆置链表)
题目链接/* Reverse a linked list and return pointer to the head The input list will have at least one element Node is defined as struct Node { int data; struct Node *next; }*/原创 2015-12-19 10:37:02 · 678 阅读 · 0 评论 -
HackerRank Find Median(中位数)
题目链接Problem StatementThe median of a finite list of numbers can be found by arranging all the integers from lowest to highest value and picking the middle one. For example, the median of{3原创 2015-12-18 22:52:43 · 437 阅读 · 0 评论 -
DSOJ Heapsort implementation(堆排序)
题目链接#include //HeapSort implementation#include#include#define MAXLEN 100001int len; //堆中的实际元素的个数void SiftDown(int *a, int index, int n){ int i, j; i = index; j = 2 * i; a[0] = a[i];原创 2015-12-19 14:00:07 · 595 阅读 · 0 评论 -
HackerRank Self Balancing Tree(AVL树)
题目链接/* Node is defined as :typedef struct node{ int val; struct node* left; struct node* right; int ht;} node; */int Height(node *T){ if (!T) return -1; //In this qu原创 2015-12-19 22:21:07 · 508 阅读 · 0 评论 -
HackerRank Largest Rectangle
题目链接Problem StatementThere are N buildings in a certain two-dimensional landscape. Each building has a height given byhi,i∈[1,N]. If you join K adjacent buildings, they will form a原创 2015-12-18 21:56:20 · 391 阅读 · 0 评论 -
51Nod 逆序数
题目链接#include //求逆序数#define MAX 50001/*算法思想:利用归并排序的算法思想:归并排序是将带排序序列分为若干个子序列,每个子序列是有序的,然后再把有序的子序列逐步合并成为整体有序序列因此可利用归并排序的算法框架,依次计算小序列的逆序数,最终求得大序列的逆序数*/long long count;int a[MAX], b[MAX];原创 2015-12-19 13:50:07 · 376 阅读 · 0 评论 -
DSOJ 中缀表达式求值
题目链接#include //中缀表达式求值#include#include#define MAX 600char Infix[MAX];char Postfix[2 * MAX]; //在操作数及操作符之后都加一个空格int StrToInt(char *s, int begin, int end) //字符串转化为int型数据,处理操作数为多位数的情形{ int原创 2015-12-19 23:09:02 · 1277 阅读 · 0 评论 -
DSOJ Placing apples(放苹果)
题目链接#include //Placing Apples/* 解题分析: 设f(m,n) 为m个苹果,n个盘子的放法数目,则先对n作讨论, 当n>m:必定有n-m个盘子永远空着,去掉它们对摆放苹果方法数目不产生影响。即if(n>m) f(m,n) = f(m,m) 当n<=m:不同的放法可以分成两类: 1、有至原创 2015-12-19 23:07:29 · 683 阅读 · 0 评论 -
DSOJ Topological Sort(拓扑排序)
题目链接#include //Topological Sort(利用小顶堆使同等条件下,编号小的顶点在前)#include#include#define MAX 100 //最大的顶点个数typedef struct arc{ int index; struct arc *next;}Arc;typedef struct graph{ int vexnum,原创 2015-12-19 23:05:11 · 524 阅读 · 0 评论 -
DSOJ I Love PKU(我爱北大)
题目链接#include //I love PKU#include#include#define INFINITE 9999999#define MaxVexnum 30 //顶点的最大个数#define MaxArcnum 50 //边的最大个数typedef struct graph{ int vexnum, arcnum; char *vexname[MaxVe原创 2015-12-19 23:03:22 · 1073 阅读 · 0 评论 -
DSOJ Specular reflection of a tree(树的镜面映射)
题目链接#include //Specular reflection of a tree#include#include#define MAX 100 //树的最大结点数typedef struct node{ char info; int level; //记录结点所在的层数,便于控制输出树的镜面映射的广度优先遍历 struct node *left, *原创 2015-12-19 23:01:51 · 850 阅读 · 0 评论 -
DSOJ Level-order sequence with degree(森林的带度数层次遍历序列)
题目链接#include //Level-order sequence with degree(森林的带度数层次序列存储)#include#include //算法思想:利用队列存储输入的带度数的层次遍历序列,从队首开始遍历队列,#define MAX 100 //根据结点度数的不同进行相应的处理int N; //The number of treesin原创 2015-12-19 23:00:44 · 978 阅读 · 0 评论 -
DSOJ BST(二叉搜索树)
题目链接#include //Binary Search Tree#includetypedef struct node{ int data; struct node *left, *right;}BST;BST *insert(BST *T, int key) //Insert{ if (!T) { T = (BST *)malloc(sizeof(BST)原创 2015-12-19 22:58:58 · 638 阅读 · 0 评论 -
DSOJ Huffman coding tree(Huffman编码树)
题目链接#include //Huffman coding tree#include#include#define MAX 200 //The maximum number of nodetypedef struct node{ int weight; int parent, lchild, rchild; int flag;}HT;void initial(HT原创 2015-12-19 22:57:22 · 771 阅读 · 0 评论