2015年7月6日

Add Two Numbers

摘要: 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 digit. Add the two numbers and return it as a link... 阅读全文

posted @ 2015-07-06 22:00 立顿经典醇 阅读(103) 评论(0) 推荐(0)

bubble sort 冒泡排序

摘要: #include #include #include using namespace std; template void BubbleSort(list& li) { list::iterator it_left = li.begin(); list::iterator it_right = li.begin(); it_right++; bool f_s... 阅读全文

posted @ 2015-07-06 19:59 立顿经典醇 阅读(136) 评论(0) 推荐(0)

insert sort 插入排序

摘要: #pragma once #include #include template void InsertSort(list& container) { std::list::iterator it_min = container.begin(); std::list::iterator it_temp; std::list::iterator it_test; ... 阅读全文

posted @ 2015-07-06 19:53 立顿经典醇 阅读(84) 评论(0) 推荐(0)

Two Sum

摘要: Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where i... 阅读全文

posted @ 2015-07-06 19:51 立顿经典醇 阅读(128) 评论(0) 推荐(0)

selection sort 选择排序

摘要: template void SelectSort(list& container) { std::list::iterator it_min = container.begin();//待放入最小值的位 std::list::iterator it_temp = it_min;//暂存最小值 std::list::iterator it_test = it_min;//滑动... 阅读全文

posted @ 2015-07-06 19:50 立顿经典醇 阅读(123) 评论(0) 推荐(0)

数组循环右移

摘要: 题目的大意是将一个长度为n的数组A内的元素循环右移m位(当然左移也可以),比如数组 {1, 2, 3, 4, 5}右移3位之后就变成{3, 4, 5, 1, 2}。时间复杂度O(N),空间复杂度O(1)的解法:我们要做的只是把每个元素放到它应该在的位置,比如开头的例子,1应该放在4的位置,把1放好之... 阅读全文

posted @ 2015-07-06 19:14 立顿经典醇 阅读(208) 评论(1) 推荐(0)

最大公约数;最小公倍数

摘要: 辗转相除法int gcd(int m,int n){int remainder;while(remainder!=0){remiander = m%n;m = n;n = remainder;}return m;}有两整数a和b:①a%b得余数c②若c=0,则b即为两数的最大公约数③ 若c≠0,则a... 阅读全文

posted @ 2015-07-06 19:11 立顿经典醇 阅读(94) 评论(0) 推荐(0)

计算器

摘要: 通过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串。输入字符串的格式为:“操作数1 运算符 操作数2”,“操作数”与“运算符”之间以一个空格隔开。补充说明:1、操作数为正整数,不需要考虑计算结果溢出的情况。2、若输入算式格式错误,输出结果为“0”。要求实现函数:void a... 阅读全文

posted @ 2015-07-06 19:05 立顿经典醇 阅读(118) 评论(0) 推荐(0)

华为提前批机试题整理

摘要: 1. 输入字符串,输出字符串中重复出现过的字符,每个只输出一次思路:将出现过的字符生成一个字典,并统计出现次数,超过一次出现的直接输出#include#includeusingnamespace std;int main(){string inputStr;string dicStr;string ... 阅读全文

posted @ 2015-07-06 18:57 立顿经典醇 阅读(252) 评论(0) 推荐(0)

虚函数virtual function与多态(polymorphism)

摘要: 类继承:派生类(derived类)继承了基类(base类),基类中可能存在多态的函数声明为虚函数多态性可以简单地概括为“一个接口,多种方法”,程序在运行时才决定调用的函数,它是面向对象编程领域的核心概念。多态(polymorphism),字面意思多种形状。 C++多态性是通过虚函数来实现的,虚函数允许子类重新定义成员函数,而子类重新定义父类的做法称为覆盖(override),或者称为重写。(这里... 阅读全文

posted @ 2015-07-06 18:55 立顿经典醇 阅读(140) 评论(0) 推荐(0)

导航