随笔分类 - 数据结构
摘要:最近在练习使用STL中德各种容器,像vector,map,set之类的。然后在使用vector的时候,无意间遇到了一个很二逼的问题。主要是这样的,请看源码(C++)://错误的写法:
#include "stdafx.h" #include
#include
#include using namespace std; int main()
{ vector MyVector; //这里是没有申明数量的,而下面用的下标访问,会出现错误 for(int i=0;i>a; return 0;
} //改进的方法一
#include
#include
#include ...
阅读全文
摘要:本文主要是使用了STL中德map和set两个容器,使用了它们本身的一些功能函数(包括迭代器),介绍了它们的基本使用方式,是一个使用熟悉的过程。map的基本使用:#include "stdafx.h"
#include
#include
#include
#include
#include using namespace std; int main() { //定义map对象 map myMap; myMap["jack"]=98.5; myMap["bomi"]=98.0; myMap["Kate"]=97.6;
阅读全文
摘要:以下是使用STL中map类型,对类型的转换示例,主要可以解决的问题,也就是一般的类型之间的相互转换,可以较好的解决相关的问题。以下是C++源码,比较简短,容易理解的。#include "stdafx.h"
#include
#include
#include
#include
#include using namespace std; int main() { //定义map对象,将字符映射成为数字 map cTi; for(int i=0;i iTc; for(int i=0;i>k; return 0;
}
一些细节的地方说明,请看源码中的注释...
阅读全文
摘要:选择排序、快速排序、希尔排序、堆排序不是稳定的排序算法,冒泡排序、插入排序、归并排序和基数排序是稳定的排序算法。冒泡排序是稳定的,算法时间复杂度是O(n ^2)。 2.2 选择排序(Selection Sort) 选择排序的基本思想是对待排序的记录序列进行n-1遍的处理,第i遍处理是将L[i..n]中最小者与L[i]交换位置。这样,经过i遍处理之后,前i个记录的位置已经是正确的了。 选择排序是不稳定的,算法复杂度是O(n ^2 )。2.3 插入排序 (Insertion Sort) 插入排序的基本思想是,经过i-1遍处理后,L[1..i-1]己排好序。第i遍处理仅将L[i]插入L[1..i-1
阅读全文
摘要:下面是继续写的数据结构中双向链表的类(还有部分有些问题,待将所有的数据结构实现之后统一测试和修改)(记得未测试哦。)//公元2013年3月17日
//Single List--By Paul #ifndef _DoubleList_
#define _DoubleList_ #include
using namespace std; template class DoubleList;
//结点类 template class ListNode
{
private: Type data; ListNode *Previous; ListNode *Next;
private...
阅读全文
摘要:数据结构单链表的C++实现://公元2013年3月17日
//Single List--By Paul #ifndef _SingleList_
#define _SingleList_ #include
using namespace std;
template class SingleList; //结点类。。。
template class ListNode{
private: Type data; ListNode *pnext;
private: friend typename SingleList; ListNode():pnext(null){} ListNo...
阅读全文
摘要:最近准备找工作了,在复习数据结构,下面是用C++写的顺序表的一个类(头文件)//公元2013年3月15日
//Sequence List--By Paul #ifndef _SeqList_
#define _SeqList_ const int defaultSize=100; template class SeqList{
public: SeqList(int SZ=defaultSize):m_nmaxsize(SZ),m_ncurrentsize(-1){ if (SZ>0){ m_elements=new Type[m_nmaxsize]; } } ~...
阅读全文

浙公网安备 33010602011771号