随笔分类 -  C/C++

C/C++ Application
摘要:深度优先搜索算法(转)深度优先搜索算法需要了解深度优先遍历的执行过程,本文中利用一个栈来模拟递归实现中系统设置的工作栈,算法的伪代码描述为: (1)初始化栈 (2)输出起始节点,并标记为已访问,将该节点压入栈 (3)While(栈不为空) a.取得栈顶节点Top,注意不要从站内删除; b.遍历栈顶节点Top的相邻节点adjacentNode,如果该节点adjacentNode未被标记为已 访问,则 输出节点adjacentNode; 标记adjacentNode为已访问; 把adjacentNode压入栈; c.如果没有满足条件的相邻节点adjacentNode,将栈顶节点Top出栈;使用情形 阅读全文
posted @ 2013-08-20 23:10 强子~Developer 阅读(538) 评论(0) 推荐(0)
摘要:广度优先算法(转)http://blog.csdn.net/furturerock/article/details/5568305空间复杂度因为所有节点都必须被储存,因此BFS的空间复杂度为 O(|V| + |E|),其中 |V| 是节点的数目,而 |E| 是图中边的数目。注:另一种说法称BFS的空间复杂度为O(BM),其中 B 是最大分支系数,而 M 是树的最长路径长度。由于对空间的大量需求,因此BFS并不适合解非常大的问题。时间复杂度最差情形下,BFS必须寻找所有到可能节点的所有路径,因此其时间复杂度为 O(|V| + |E|),其中 |V| 是节点的数目,而 |E| 是图中边的数目。若所 阅读全文
posted @ 2013-08-20 18:21 强子~Developer 阅读(1135) 评论(0) 推荐(0)
摘要:-------------------Floyd-Warshall算法,简称Floyd算法,用于求解任意两点间的最短距离,时间复杂度为O(n^3)。对上面这个图的程序/* * main.cpp * * Created on: 2013-8-18 * Author: 白强 */#include using namespace std;const int INF = 100000;int n = 10, map[11][11], dist[11][11][11];//初始化路径void init() { int i, j; for (i = 1; i > u >> v, u... 阅读全文
posted @ 2013-08-18 17:15 强子~Developer 阅读(273) 评论(0) 推荐(0)
摘要:数据结构学过好多时了,都快忘记了,现在复习一下吧摘自http://www.wutianqi.comDijkstra(迪杰斯特拉)算法是典型的最短路径路由算法,用于计算一个节点到其他所有节点的最短路径。主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止。Dijkstra算法能得出最短路径的最优解,但由于它遍历计算的节点很多,所以效率低。其基本思想是,设置顶点集合S并不断地作贪心选择来扩充这个集合。一个顶点属于集合S当且仅当从源到该顶点的最短路径长度已知。初始时,S中仅含有源。设u是G的某一个顶点,把从源到u且中间只经过S中顶点的路称为从源到u的特殊路径,并用数组dist记录当前每个顶点所对 阅读全文
posted @ 2013-08-18 11:15 强子~Developer 阅读(560) 评论(0) 推荐(0)
摘要:今天的主要是优先级队列的使用priority_queue学习使用简单的形式头文件:#include<queue>优先队列,也就是原来我们学过的堆,按照自己定义的优先级出队时。默认情况下底层是以Vector实现的heap。函数列表: empty() 如果优先队列为空,则返回真 pop() 删除第一个元素 push() 加入一个元素 size() 返回优先队列中拥有的元素的个数 top() 返回优先队列中有最高优先级的元素优先队列有入队、出队、判空、大小的操作,并不具备查找功能。一个我写的简单例子#include <iostream>#include<queue> 阅读全文
posted @ 2013-05-31 14:46 强子~Developer 阅读(372) 评论(0) 推荐(0)
摘要:学习使用STL sort和find函数list有两个版本的sort成员函数: 一个是不带参数的sort(),用来实现升序排列; 另一个是带参数的sort(greater<T> pr),用来实现降序排列。Algorithms中的的Sort方法,也是我们这次实验的排序方法下面的两参数的就是默认的排序,指定迭代器的初始与末尾void sort( iterator start, iterator end );三个参数的最后一个参数是bool类型的函数,用函数指定排序规则:如下所示void sort( iterator start, iterator end, StrictWeakOrder 阅读全文
posted @ 2013-05-18 15:30 强子~Developer 阅读(428) 评论(0) 推荐(0)
摘要:Exam2下来就是Optional Exercise6,这是一个以树和StL map组合的数据结构,并要求递归来求解问题具体看题目吧它先是给了数据描述对definitions.txt的叙述hospital 10 floorfloor 4 wingwing 2 long_corridorwing 1 connecting_corridorlong_corridor 21 patient_roomconnecting_corridor 5 supply_roompatient_room 2 bedpatient_room 4 outletpatient_room 1 bathroomoutlet 阅读全文
posted @ 2013-05-18 14:29 强子~Developer 阅读(801) 评论(0) 推荐(0)
摘要:这个是STL的堆栈适配器练习看一下它给的描述吧DescriptionThis assessment tests your ability to use the STL stack adapter, the STL vector container, and the STL find algorithm to solve a problem. You are asked to finish the implementation of a program that simulates a multiple-aisle parking lot. When cars are parked bumper 阅读全文
posted @ 2013-05-06 17:26 强子~Developer 阅读(647) 评论(0) 推荐(0)
摘要:欢迎访问我的博客,接下来就是第十一周的Optional Exercise 5了这个题目是要求我们学会排序算法--------选择排序和快速排序,具体算法也不用自己写,只是看就可以了,自己要写的真的不多,比较简单题目是根据很多的数据排序来反映选择排序与快速排序的时间复杂度的不同DescriptionThe program to be completed for this assessment demonstrates the runtime differences between a stable and non-stable sort. The stable sort examined in 阅读全文
posted @ 2013-05-06 16:58 强子~Developer 阅读(729) 评论(1) 推荐(1)
摘要:这个拼写检查的程序原理上没有什么难度却看不大懂这个hashset,求大神指点hashset.h// template hash set class#ifndef _HASHSET_H_#define _HASHSET_H_#include <iostream>#include <vector>#include <algorithm>#include <stdexcept>using namespace std;// we do not compute prime numbers but use a table insteadstatic cons 阅读全文
posted @ 2013-05-05 12:33 强子~Developer 阅读(627) 评论(0) 推荐(0)
摘要:这题还是接着Exercise1和Exercise2来的,没什么难的,照着它给的头文件补充好函数就可以了本题给了两个头文件 Category.h和Categories.h看一下题目给的提示Class CategoryClass Category models a category. This class contains private data members for the category name, identification number, and parent identification number. A vector<int> stores the unique 阅读全文
posted @ 2013-05-03 14:43 强子~Developer 阅读(580) 评论(0) 推荐(0)
摘要:STL = Standard Template Library,标准模板库,STL的目的是标准化组件,这样就不用重新开发,可以使用现成的组件。STL现在是C++的一部分,因此不用额外安装什么。在C++标准中,STL被组织为下面的13个头文件:<algorithm>、<deque>、<functional>、<iterator>、<vector>、<list>、<map>、<memory>、<numeric>、<queue>、<set>、<stack>和 阅读全文
posted @ 2013-04-22 11:48 强子~Developer 阅读(383) 评论(0) 推荐(0)
摘要:这个题文件给了一大堆,其实最关键的只有两个Listing.h及Group.hclass Listing and class Group题目总的来说是比较好的,可惜我运行不成功,所以在此只好把要做的事情做好先看Class ListingClass Listing models a collection of advertisements. This class contains a private data member of type vector<Advertisement*>. This vector stores pointers to Advertisement objec 阅读全文
posted @ 2013-04-21 14:14 强子~Developer 阅读(429) 评论(0) 推荐(0)
摘要:这个题目是一个评估感染的问题主要用到STL的Vector和分治法思想及迭代背景就不管了看一下描述DescriptionThis assignment asks you to finish the implementation of a program that assesses the level of infection in a tissue sample. You are given data representing a rectangular tissue sample, overlaid with a grid. Certain portions of the tissue are 阅读全文
posted @ 2013-04-21 13:50 强子~Developer 阅读(1010) 评论(0) 推荐(0)
摘要:有过对STL的栈练习,当然就少不了队列了看一下题目总体要求BackgroundFrom store-and-forward queues in network routers to the facilitation of breadth-first searches in graph algorithms, queues have many important applications in Computer Science and Information Technology. One such application can be found in a policy used by net 阅读全文
posted @ 2013-04-18 22:43 强子~Developer 阅读(848) 评论(0) 推荐(0)
摘要:这个题主要考察对继承的掌握还有动态存储和异常处理按照步骤一步步来做这个题Extract the archive to retrieve the files needed to complete this assessment我们得到LinkedList.h,我还给了相应的注释#ifndef _LINKEDLIST_H_#define _LINKEDLIST_H_#include <stdexcept>/* * 作者:白强 * 日期:2013/4/18 * 这是题目给的一个数据结构实现 * 它可以在链尾或链头插入和删除元素 * virtual void push_front(T); 阅读全文
posted @ 2013-04-18 00:59 强子~Developer 阅读(517) 评论(0) 推荐(0)
摘要:1.先来看一下题目要求 To complete this assessment, you will need to design and implement class Car and implement the parking-lot simulator program. To begin, verify the files needed for this assessment.Extract the archive to retrieve the files needed to complete this assessment.Following is an ordered list .. 阅读全文
posted @ 2013-04-17 23:28 强子~Developer 阅读(1326) 评论(1) 推荐(0)
摘要:直接上代码,可以自己慢慢研究#include <iostream>#include <stdlib.h>using namespace std;int LineNum[9]; //第i列的皇后要放的行位置(只用其中的列号1到8)bool a[9]; //a[i]为1表示第i行上尚未放皇后bool b[15]; //b[i]为1表示第i条斜对角线上尚未放皇后(斜对角线指的是"/"状对角线,该对角线上各点的行列号之和i+j为一个常数)bool c[15]; //c[i]为1表示第i条反斜对角线... 阅读全文
posted @ 2013-04-09 22:24 强子~Developer 阅读(359) 评论(0) 推荐(0)
摘要:#include <iostream>#include <cstdlib>using namespace std;const int DefaultSize=100;template <class T>struct Trituple{ int row,col; T value; Trituple<T>& operator =(Trituple<T>& x){ row=x.row;col=x.rol;value=x.value; }};template <class T>class SparseMatrix{ 阅读全文
posted @ 2013-04-09 22:23 强子~Developer 阅读(164) 评论(0) 推荐(0)