- 博客(13)
- 收藏
- 关注
原创 二分查找(C语言)
【问题描述】请写一非递归算法,该算法在按值严格递增排列的顺序表A[1..n]中采用折半查找法查找值不小于item的最小元素。若表中存在这样的元素,则算法给出该最小元素在表中的位置,否则,给出信息为0.【输入形式】按值严格递增排列的顺序表A[1..n]【输出形式】不小于item的最小元素在表A中的位置,若不存在,则给出信息0【样例输入】2 4 6 8 10 3【样例输出】2【样例说明】位置从1开始#include <stdio.h>#...
2021-12-18 17:34:04
791
原创 整数翻转(翻转后可能会有溢出)
题目描述(中文)给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转后的结果。如果反转后整数超过 32 位的有符号整数的范围[−231,231− 1] ,就返回 0。假设环境不允许存储 64 位整数(有符号或无符号)。(English)Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the s...
2021-12-13 23:56:45
923
原创 两数之和(将数据放入vector容器中)
LeetCode算法题:题目描述(中文):给定一个整数数组 nums和一个整数目标值 target,请你在该数组中找出 和为目标值 target的那两个整数,并返回它们的数组下标。你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。你可以按任意顺序返回答案。English:Given an array of integers numsand an integer target, return indices of the two numbers...
2021-12-13 17:28:28
353
原创 Queue容器
#include <iostream>#include <queue>#include <string>using namespace std;/** \brief Queue *@NWNU ziyif *///Queue FIFO//Queue容器允许从一端push数据,另一端pop数据//Queue容器只有队头front和队尾back能够被外界访问,所以Queue也不能遍历class Person{public: Person(s.
2021-12-11 23:59:43
182
原创 stack容器
STL中的stack容器的常用接口较少且简单,又由于在本学期的DS课中已经学过stack数据结构,所以用起来真是既方便又简单。#include <iostream>#include <stack>using namespace std;// 由于栈的FILO以及弹出的性质,使得栈不会有遍历// 栈可以返回元素个数(在入栈的时候记录)/** \brief stack *@NWNU ziyif */void try1();int main(){ t
2021-12-11 23:34:58
156
原创 二分查找(C++)
输入10个数,输入想要找的数,得出其在数组中的位置。#include <iostream>#include <vector>using namespace std;/** *@NWNU ziyif */class Sloution{public: int BinSearch(vector<int> &nums,int target){ int pos=-1; bool temp=false;
2021-12-06 23:01:35
563
原创 vector容器
#include <iostream>#include <vector>using namespace std;/** *@NWNU ziyif *///vector也称为单端数组,它可以 动态扩展:并不是在原空间续接新空间,而是找更大的内存空间,然后将原数据copy到新空间,释放原空间//vector的迭代器是支持随机访问的迭代器//vector中的数据只能从尾部压入数据和弹出数据(类似栈),头部封着void PrintVector(vector<i.
2021-12-06 00:27:48
831
原创 string容器相关操作
#include <iostream>#include <string>using namespace std;/** *@NWNU ZIYIF *///string本身是一个类//string类中封装了很多成员方法,ex:find,copy,delete,replace,insert//char*是个指针,string是一个类,类内部封装了char*,管理这个字符串,是一个char*型容器void try1();//string的构造void try2.
2021-12-05 00:21:19
217
原创 初识STL(以vector容器为例)
对算法标准库中的for_each()函数接口并不能正确理解和使用。#include <iostream>#include <vector>#include <algorithm>#include <string>using namespace std;/** *@NWNU ziyif *///STL(Standard Template Library,标准模板库)//STL六大组件:容器、算法、迭代器、仿函数、适配器、空间配置器/
2021-12-02 17:28:04
116
原创 二叉树的简单操作
实现二叉树的基本操作:初始化、创建二叉树、判别二叉树是否为空、3种遍历的递归算法、统计创建的二叉树的结点和叶子结点的个数、求二叉树的深度。#include <stdio.h>#include <stdlib.h>/** *ziyif */typedef char TElemType;typedef struct BiTNode{ TElemType data; struct BiTNode *lchild, *rchild;}BiTNode,*
2021-12-01 18:15:54
161
原创 求节点的哈夫曼的带权路径长度
【问题描述】已知输入一串正整数,正整数之间用空格键分开,请建立一个哈夫曼树,以输入的数字为叶节点,求这棵哈夫曼树的带权路径长度。【输入形式】首先输入正整数的个数,然后接下来为接下来的正整数,正整数个数不超过10个【输出形式】输出相应的权值【样例输入】5 4 5 6 7 8【样例输出】69#include <stdio.h>#include <stdlib.h>/** *@ziyif */typedef int QElemType...
2021-12-01 16:46:40
1250
1
原创 已知一个二叉树的中序遍历序列和后序遍历序列,求这棵树的前序遍历序列
#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_SIZE 100typedef char TElemType;typedef struct BiTnode{ TElemType data; struct BiTnode *lchild; struct BiTnode *rchild;}BiTNode;BiTNode* Build(int le.
2021-11-29 17:51:32
1455
原创 链队列的简单操作
#include <stdio.h>#include <stdlib.h>/** *zi */typedef int QElemType;typedef struct Qnode{ QElemType data; struct Qnode *next;}QNode,*QueuePtr;typedef struct{ QueuePtr front;//队头指针 QueuePtr rear;//队尾指针}LinkQueue;vo.
2021-10-28 17:36:43
124
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人