CareerCup Chapter 9 Sorting and Searching】的更多相关文章

9.1 You are given two sorted arrays, A and B, and A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order. A has enough buffer at the end to hold B, we can merge two arrays from end to start index, like merg…
Algorithm in Practice Author: Zhong-Liang Xiang Date: Aug. 1st, 2017 不完整, 部分排序和查询算法, 需添加. Prerequisite 生成随机整数数组,打印数组, 元素交换. #include <stdlib.h> #include <iostream> #include <time.h> using namespace std; #define MAX 10 // 数组最大长度 void init…
Experiment report of Besti course:<Program Design & Data Structures> Class: 1623 Student Name: Wang, Yixiao Student Number:20162314 Tutor:Mr.Lou.Mr.Wang Experiment date:2017.11.6 Secret level: Unsecretive Experiment time:60 minutes Major/Electiv…
Common Sorting Algo: Bubble Sort: Runime: O(n2) average and worst case. Memory: O(1). void BubbleSortArray(){ for(int i=1;i<n;i++) for(int j=0;i<n-i;j++) if(a[j]>a[j+1]){//比较交换相邻元素 int temp; temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } Selection Sort…
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Build in functions in java.util.Collections Need to implement a comparator - a special class which returns an integer comparision of two object, if  compare(a,b), if return negative number, a will be before b, otherw…
1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures? 字符串问题,需要先确定是不是只有ASCII码. 如果是,可以用char[256],也可以用位向量.位向量的实现参照<编程珠玑>.i&MASK就是取余.i>>SHIFT就是取商. class BitVector { pu…
3.1 Describe how you could use a single array to implement three stacks. Flexible Divisions的方案,当某个栈满了之后,需要把相邻的栈调整好,这是一个递归的过程. 每个stack有一些属性,所以不妨将每个stack封闭起来,我这里是用一个private的struct来实现,方便,同时对外部又不可见. 对于一些常用的操作,比如环形数组取下一个数,前一个数,都可以封装起来. class XNStack { pub…
链表的题里面,快慢指针.双指针用得很多. 2.1 Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed? 2.2 Implement an algorithm to find the kth to last element of a singly linked list.…
8.2 Imagine you have a call center with three levels of employees: respondent, manager, and director. An incoming telephone call must be first allocated to a respondent who is free. If the respondent can't handle the call, he or she must escalate the…
7.4 Write methods to implement the multiply, subtract, and divide operations for integers. Use only the add operator. 比较简单.但是要封装得好. 7.5 Given two squares on a two-dimensional plane, find a line that would cut these two squares in half. Assume that th…