C++实现树的基本操作,界面友好,操作方便,运行流畅,运用模板

Ⅰ.说明: 1.采用左孩子右兄弟的方式,转化为二叉树来实现。 2.树的后根遍历与二叉树的中根遍历即有联系又有区别,请读者注意分析体会。 Ⅱ.功能: 1.创建树并写入数据 2.先根遍历树 3.计算树高 4.后根遍历树 5.层次遍历树 6.搜索数据域为某值的结点 7.删除数据域为某值的结点及其子树 8.销毁树 Ⅲ.代码: //.h文件 #if...

C++实现有向权图的基本操作,界面友好,操作方便,运行流畅

Ⅰ.功能: 1.创建图 2.展示全图 3.添加顶点 4.添加边 5.删除顶点 6.删除边 7.查看指定边权值 8.修改指定边权值 9.输出两点间的所有简单路及路径对应权值 10.销毁图 ps:关于9,如果不存在任何简单路,输出“不存...

致广大读者的一封公开道歉信

广大读者大家好!在下是博主同勉共进,在在下先前发布的博文《C++实现二叉树,运用模板,界面友好,操作方便 运行流畅》中,在清空队列函数Delq()和清空DQNode队列函数Deld()中,将while错写为if,从而导致了内存泄露的问题。不久前在下浏览自己博客时发现了这一错误。在下现已将代码改正,在此特作说明,并向广大读者致以真诚的歉意,希望广大读者不要受到误导。同时,在下向大家保证以后会最大限度地避免类似错误的发生,向大家提供高质量的代码。希望大家继续关注在下的博客。谢谢大家!
公告声明 | 2014-11-18 16:57 | 阅读 982 次 | 评论 0 条

C语言实现数组快速排序(含对算法的详细解释)

/* 说明: 代码参考过网上代码,但分析为个人原创,本贴重在说明快速排序算法的思想和运行过程。 */ 代码部分: #include<stdio.h> #include<stdlib.h> void quickSort(int* arr,int startPos, int endPos) { int i, j; int key; key = arr[startPos]; i = startPos; j = endPos; while (i<j) { while (arr[j...
C语言快排 | 2014-11-02 00:14 | 阅读 1364 次 | 评论 0 条

C语言实现单向链表及其各种排序(含快排,选择,插入,冒泡)

#include<stdio.h> #include<malloc.h> #define LEN sizeof(struct Student) struct Student //结构体声明 { long num; int score; struct Student* next; }; int n; struct Student* creat() //创建单向链表 { struct Student *head=NULL, *p_before, *p_later; p_before ...

C++,利用链式栈实现括号匹配,界面友好,操作方便,运行流畅

#include<iostream> #include<string> using namespace std; struct Node { char ch; Node* next; Node(char c, Node* p){ ch = c; next = p; } }; void main() { string str; bool flag = true; while (flag) { cout << "请输入算术表达式:" << endl; getline(cin, str); int l...

C++,数据结构,单向链表的实现及简单运用,运用模板

/* 代码功能: 1.链接存储方式实现单向链表(表头含有一个空结点作为哨位结点) 2.将另一数组中的数据读入该链表 3.链表数据排序(插入排序) 4.从外界插入一个数据,并使插入后的链表依然有序 5.实现过程中运用了模板 备注:按课程要求做的,有点糙。 */ //.h文件 #ifndef LIST_H #define LIST_H #include<iostream> template<typename T> struct Node_for_List ...

C++实现链式栈,运用模板,界面友好,操作方便,运行流畅

//.h文件 #ifndef STACK_H #define STACK_H #include<iostream> #include<iomanip> using namespace std; template<typename T> //链式栈结点 struct L_Node { T data; L_Node<T>* next; L_Node(); L_Node(const T&amp;item,L_Node<T>* next=NULL); //重载构造函数 }; ...

C++实现顺序栈,运用模板,界面友好,操作方便,运行流畅

//.h文件 #ifndef STACK_H #define STACK_H #include<iostream> template <typename T> class Stack { private: T* array; int size; int top; private: bool Push(const T&amp; item); bool Pop(T&amp; item); bool Creat(const int&amp; num); bool IfEmpty()const; bool I...

C++实现二叉树,运用模板,界面友好,操作方便 运行流畅

//.h文件 #ifndef TREE_H #define TREE_H #include<iostream> #include<iomanip> using namespace std; template<typename T> struct Node //树结点 { T data; Node<T> *left, *right; Node(const T&amp; item); }; template<typename T> Node<T>::Node(const T&amp; item) ...
文章归档
最新评论