![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
小飞将
一切过往,皆为序章
展开
-
链表节点Node为结构体,内部包含前向和后向Node指针的结构体定义方式
【代码】链表节点Node为结构体,内部包含前向和后向Node指针的结构体定义方式。原创 2023-11-29 15:04:10 · 140 阅读 · 0 评论 -
数组实现可扩展的循环队列
arrayQueue.h// circular array implementation of a queue// derives from the ADT queue#ifndef arrayQueue_#define arrayQueue_#include "queue.h"#include "myExceptions.h"#include <sstream>using namespace std;template<class T>class arra转载 2020-12-30 13:55:40 · 318 阅读 · 0 评论 -
数组结构的栈实现
Stack.h#pragma oncetemplate <class T>class Stack {public: virtual void clear() = 0; // clean the stack virtual void push(const T&) = 0; // push T into stack virtual void pop() = 0; // pop top item in stack virtual T& top() = 0;原创 2020-12-28 23:07:07 · 98 阅读 · 0 评论 -
汉诺塔问题的递归实现
// TowersOfHanoi.cpp : This file contains the 'main' function. Program execution begins and ends there.//#include <iostream>#include <chrono>void towersOfHanoi(int n, int t1, int t2, int t3) { //将t1上所有盘移到t2 if (n > 0) {原创 2020-12-27 17:46:30 · 106 阅读 · 1 评论 -
链表的模板实现
BaseList.h#pragma oncetemplate <class T>class BaseList {public: typedef size_t pos; virtual void clear() = 0; // empty the list virtual bool isEmpty() = 0; // Is empty list? virtual void append(const T&) = 0; // add element原创 2020-12-26 18:33:29 · 170 阅读 · 0 评论 -
线性表的实现
ListBase.h// abstract data type for List template <class T> class List { void clear(); // 置空线性表 bool isEmpty(); // 线性表为空时,返回True bool append(T value); // 在表尾添加一个元素value,表的长度增1 bool insert(int p, T value);原创 2020-12-25 18:05:45 · 75 阅读 · 0 评论 -
List 链表的实现
List.h#include <stdbool.h>#ifndef _LIST_Hstruct Node;typedef struct Node *PtrToNode;typedef PtrToNode List;typedef PtrToNode Position;struct Node { int Element; Position Next;};List MakeEmpty(List L);bool IsEmpty(List L);bool原创 2020-07-20 23:22:49 · 287 阅读 · 0 评论 -
斐波纳锲数列
斐波纳锲数列:fab.h#pragma once#include <iostream>#include <string>template <typename T>T fab(T n) { if (n == 0) return 0; if (n == 1) return 1; return fab(n - 1) + fab(n...原创 2019-12-01 18:20:39 · 290 阅读 · 0 评论 -
C++ replace string
搜索指定字符串,并以新字符串替换void replaceStr(string &s, string &oldStr, string &newStr) { for ( string::iterator itr = s.begin(); itr != s.end(); ++itr ) { if (*itr...原创 2019-08-13 23:46:57 · 827 阅读 · 0 评论 -
最大正方形
遍历二维数组中的所有点,对每一个点:判断对角线元素是否为1,接着判断右边和底边是否为1class Solution {public: void checkMatrix(vector<vector<char>> &v, unsigned int i, unsigned int j, unsigned int rowLength, unsigned int...原创 2019-08-04 22:40:40 · 94 阅读 · 0 评论 -
Valid Parentheses
class Solution {public: bool isValid(string s) { if (s.empty()) {return true;} stack<char> t; for (auto itr = s.begin(); itr != s.end(); ++itr) { if (*it...原创 2019-07-10 19:19:38 · 78 阅读 · 0 评论 -
Longest Common Prefix
重点在于common prefix,如果字符串数组中没有共同前缀,返回的是空。class Solution {public: size_t shorterStrSize(const string &s1, const string &s2) { return (s1.size() < s2.size() ? s1.size() : s2.size...原创 2019-07-05 00:45:41 · 132 阅读 · 0 评论 -
Search in Rotated Sorted Array
以中间位置分界,左右两边一定有一边是有序的,在有序的边界中搜索,如果没有则转到另一边搜索;无序的另一边使用同样的算法继续求解。class Solution {public:int binSearch(vector<int> &v, int target, int l, int r) { if (v.empty()) { return -1; } int mid...原创 2019-07-04 00:40:39 · 105 阅读 · 0 评论 -
是否是完全二叉树的两种判断方法
根据完全二叉树的特征:a. 左子树和右子树深度差值小于等于1b. 左子树比右子树深时,右子树时满树c. 左右子书一样深,左子树是满树d. 任意子树不存在right heavy的情况,右子树节点个数不大于左子树/** * Definition for a binary tree node. * struct TreeNode { * int val; * Tre...原创 2019-06-09 11:10:59 · 1196 阅读 · 1 评论