![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++中含有头文件
文章平均质量分 70
chosen13
这个作者很懒,什么都没留下…
展开
-
名称空间
#ifndef _BS_H#define _BS_H#include //在头文件里边就不要使用using namespace std 要使用哪一个就直接用,如下边的例子所示的,namespace Bookstore // 这个是名称空间,{ class Sales_item // 这个是类的声明, { public: Sales_item(const std::stri原创 2016-03-29 13:37:15 · 176 阅读 · 0 评论 -
哈希映射
#ifndef HASHMAP_H_#define HASHMAP_H_#include templateclass HashMap // 哈希映射 速度最快,{public: HashMap(int size = 100) : arr(size) { currentSize = 0; } void Put(const Key & k,const Value & v)原创 2016-04-25 20:49:44 · 701 阅读 · 0 评论 -
自己创建一个异常
#ifndef STACK_H#define STACK_H#include #include templateclass Stack{protected: std::deque c;public: class ReadEmptyStack : public std::exception //exception 是标准异常, { public: virtual原创 2016-03-28 19:50:46 · 620 阅读 · 0 评论 -
图 - 邻接矩阵
#include #define MAX_VERTS 20using namespace std;class Vertex{public: Vertex(char lab) { Label = lab; }private: char Label; // 定义字符,};class Graph // 这是一个图,{public: Graph(); ~Graph()原创 2016-04-26 21:39:01 · 292 阅读 · 0 评论 -
链式栈
#ifndef LINKEDSTACK_H#define LINKEDSTACK_Htemplate class LinkedStack;templateclass ChainNode{ friend class LinkedStack;private: ChainNode(const T& theData, ChainNode *n = 0) : data(theData原创 2016-04-11 22:03:39 · 246 阅读 · 0 评论 -
数据结构 二叉树
#ifndef _二叉树_H#define _二叉树_H#include #include // 队列,template class BinaryTree;templateclass TreeNode // 这个类用来表示子节点,{public: TreeNode() { leftChild = NULL; rightChild = NULL; } T原创 2016-04-15 21:25:19 · 178 阅读 · 0 评论 -
CStash 的例子
typedef struct CStashTag{ int size; int quantity; int next; unsigned char* storage;}CStash;void initialize(CStash* s, int size);int add(CStash* s, const void* element);void inflate(CStash* s原创 2016-04-29 21:38:57 · 481 阅读 · 0 评论 -
二叉查找树
#ifndef 二叉查找树_H_#define 二叉查找树_H_#include // 在头文件中不要用using namespace std; 容易产生错误,enum Boolean {FALSE,TRUE};templateclass Element{public: Type key; // key是键值, // 添加更多的数据,};template cla原创 2016-04-19 20:37:05 · 187 阅读 · 0 评论 -
指针的Stash 将void** 删除指针
#ifndef STASH_H#define STASH_H#include namespace ThinkingInCppDemoLib{ class PStash { private: int quantity; int next; void ** storage; void inflate(int increase); public: PStash()原创 2016-05-15 17:55:36 · 218 阅读 · 0 评论 -
红黑树-高级的二叉查找树
#ifndef WRAPPER_H_#define WRAPPER_H_#include "Except.h"templateclass Cref{public: Cref() : obj(NULL) {} explicit Cref(const Object & x) : obj(&x) {} const Object & get() const { if(isNu原创 2016-04-23 19:10:44 · 266 阅读 · 0 评论 -
堆的操作
#ifndef MAXHEAP_H_#define MAXHEAP_H_templateclass MaxHeap{public: MaxHeap(int mx = 10); virtual ~MaxHeap(); bool IsEmpty(); void Push(const T&); void Pop(); const T& Top() const; // Top就原创 2016-04-23 22:01:47 · 182 阅读 · 0 评论 -
堆排序
#ifndef MAXHEAP_H_#define MAXHEAP_H_templateclass MaxHeap{public: MaxHeap(int mx = 10); virtual ~MaxHeap(); bool IsEmpty(); void Push(const T&); void Pop(); const T& Top() const; // Top就原创 2016-04-24 21:44:33 · 158 阅读 · 0 评论 -
循环列表
#ifndef _LIST_H#define _LIST_H// 循环列表,template class List;template class ListIterator;templateclass ListNode{ friend class List; friend class ListIterator;private: Type data; // 节点里的数据,原创 2016-04-08 21:04:03 · 236 阅读 · 0 评论 -
顺序队列的类模板与泛型编程
#ifndef _顺序队列_H#define _顺序队列_Htemplate // 模板类,T是用来创建动态数组,class Queue{public: Queue(int queueCapacity = 10); // 队列的数量存储10个 bool IsEmpty() const; // 这是判断队列是不是空的, T& Front() const; // 这个是读取队原创 2016-03-26 14:24:22 · 301 阅读 · 0 评论 -
链式队列的类模板与泛型编程
#ifndef 链式队列_H_#define 链式队列_H_templateclass Queue{public: Queue(); ~Queue(); bool isEmpty() const; const Object & getFront() const; void enqueue(const Object & x); // enqueue 是入列,是针对于队列的是先原创 2016-03-26 17:09:14 · 341 阅读 · 0 评论 -
异常3
#ifndef STACK_H#define STACK_H#include // 保存堆栈里的数据,#include // 标准异常,template class Stack{protected: std::deque c;public: class ReadEmptyStack:public std::exception // 自己创建一个异常, { pu翻译 2016-02-20 19:54:32 · 148 阅读 · 0 评论 -
函数声明
#include using namespace std;// 函数声明,void print(int *arr, int size); // 等于viod print(int *, int);函数声明放在头文件中,需要使用的地方包含头文件,int main (){ int m[] = {0,1,2,3,4,5,6,7,8,9}; print(m, 10); return原创 2016-02-21 20:32:28 · 210 阅读 · 0 评论 -
内联函数
#include #include using namespace std;inline int sum (int a, int b)//内联函数放到头文件中,{ return a + b;}inline const string &shortString(const string &s1, const string &s2)//内联函数放到头文件中,{ return s原创 2016-02-21 20:54:00 · 162 阅读 · 0 评论 -
管理指针成员
#include #include "plain-ptr.h"#include "value-ptr.h"#include "smart-ptr.h"using namespace std;void test_AHasPtr(){ int i = 42; AHasPtr p1(&i, 42); AHasPtr p2 = p1; cout << p2.get_ptr_val(原创 2016-03-20 21:46:14 · 150 阅读 · 0 评论 -
open_file
#ifndef _GET_ H#define _GET_ H#include std::istream& get(std::istream& in);#endif#include "get.h"std::istream& get(std::istream& in){ int ival; while(in >> ival, !in.eof()) {原创 2016-02-23 19:09:27 · 837 阅读 · 0 评论 -
解引用和箭头操作符
#include #include "string.h"#include "pointer.h"using namespace std;int main (){ String s("xiaocui"); s.display(); String *ps = &s; // 这个是普通的指针,普通的指针容易产生野指针, ps->display(); try { Poin原创 2016-03-22 13:32:20 · 868 阅读 · 0 评论 -
数据结构:栈
#ifndef _MYUNTIL_#define _MYUNTIL_templatevoid ChangeSize1D(T* &a, const int oldSize, const int mewSize);templatevoid ChangeSize1D(T* &a, const int oldSize, const int mewSize){ if(newSize = 0原创 2016-04-06 20:36:04 · 198 阅读 · 0 评论 -
数据结构:队列- 顺序队列
#ifndef _顺序队列_H#define _顺序队列_Htemplate // 类模板,class Queue{public: Queue(int queueCapacity=10); bool IsEmpty() const; T& Front() const; // 队尾的数据, T& Rear() const; void Push(const T& item);原创 2016-04-06 21:52:29 · 274 阅读 · 0 评论 -
链表--单链表
#ifndef THREELETTERNODE_H#define THREELETTERNODE_Hclass ThreeLetterList{private: //嵌套类, class ThreeLetterNode { public: char data[4]; // 一个数据域, ThreeLetterNode *link; // 链接域, }; Thre原创 2016-04-07 19:16:26 · 181 阅读 · 0 评论 -
链表2
#ifndef _LIST_H#define _LIST_Htemplate class List;templateclass ListNode{ friend class List;private: Type data; // 节点里的数据, ListNode *link; // 指向下一个节点的数据, ListNode(Type);};templateclas原创 2016-04-07 21:29:57 · 182 阅读 · 0 评论 -
链式队列
#ifndef QUEUELI_H#define QUEUELI_Htemplateclass Queue{public: Queue(); ~Queue(); bool isEmpty() const; const Object & getFront() const; void enqueue(const Object & x); Object dequeue();原创 2016-04-12 15:25:49 · 179 阅读 · 0 评论 -
模板化的指针Stash
#ifndef STASH_H #define STASH_H #include namespace ThinkingInCppDemoLib{ template class PStash { private: int quantity; int next; T** storage; void inflate(int increase = incr);原创 2016-05-23 15:42:56 · 323 阅读 · 0 评论