您的位置:首页 > 编程语言 > C语言/C++

C++代码之 常用算法汇总

2015-08-18 22:07 351 查看
算法–基础

排序–插入排序–直接插入排序 代码

排序–插入排序–折半插入排序 代码

排序–插入排序–两路插入排序 代码

排序–插入排序–希尔排序 代码

排序–交换排序–冒泡排序 代码

排序–交换排序–快速排序 代码

排序–选择排序–简单选择排序 代码

排序–选择排序–堆排序 代码

算法–面试题

2015-08-20 RGB Problem, IGT –字符串类

一个字符串,里面只有三种字符RGB 所有的R都在G的前面,所有的G都在B的前面, 将给定字符串按照此规律排序。

要求不允许用辅助空间,复杂度控制在O(N),遍历一遍。

解法 1 代码

2015-08-21 longest common sub–string, IGT

Please implement a function to find the longest common sub–string of two given string.

For example:

string a: abcdefg12345

string b: cdef234

longest common sub–string:cdef

解法 1 代码

2015-08-21 Expression AmazonTest2012Q1

Question: From AmazonTest2012Q1

Given an array with positive integers and another integer.

for example{7 2 4} 9, you are required to generate an equation,

by inserting operator add (“+”) and minus (“-“) among the array.

The left side of equation are consist of the array and the right

side of equation is the integer. here the result is 7-2+4=9

Rules:

Don’t include any space in the generated equation.

In case there is no way to create the equation, please output “Invalid”.

For example {1 1} 10, output is “Invalid”

The length of the integer array is from 1 to 15( include 1 and 15). If

the length is 1, for example the input {7} 7, the output is 7=7

There is no operator “+” or “-” in front of the first number:

Don’t change the order of the numbers. For example: {7 2 4} 9. 7-2+4=9 is

correct answer, 4-2+7=9 is wrong answer.

There could be multiple input, meaning your function could be called

multiple times. Do remember print a new line after the call.

[解法 1 代码] Working

2015-08-25 字符串中包含唯一字符的最长子串

Question: Given a string, find the longest sub sequence

which contains only unique characters.

解法 1 代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  算法 c++