![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
好喜欢吃红柚子
行到水穷处,坐看云起时
展开
-
sdut oj 顺序表应用4:元素位置互换之逆置算法
第一版 (超时)#include<stdio.h>#include<stdlib.h>typedef struct{ int data[100010]; int length;}sqlist;void initial(sqlist &l,int n){ l.length=n;}void create(sqlist &l){ int i; for(i=1;i<=l.length;i++)原创 2021-03-14 13:16:09 · 137 阅读 · 0 评论 -
数据结构一:顺序表
一、顺序表的创建和初始化1. 数组法typedef struct{ int elem[100]; //使用数组,直接定义了目前最大存储量和首地址,比指针法简单 int length;}sqlist;void initlist(sqlist L){ L.length=0;}2. 指针法#define MAX 100; //最大存储量#define LISTINCREMENT 10; //增加存储量个数typedef struct{ int原创 2021-03-11 18:41:59 · 270 阅读 · 0 评论 -
sdut oj 顺序表应用3:元素位置互换之移位算法
AC#include<stdio.h>#include<stdlib.h>typedef struct{ int data[100010]; int length;}sqlist;void initial(sqlist &l,int n){ l.length=n;}void create(sqlist &l){ int i; for(i=1;i<=l.length;i++) scanf.原创 2021-03-14 13:19:31 · 115 阅读 · 0 评论 -
sdut oj 数据结构实验之链表一:顺序建立链表
AC#include <iostream>using namespace std;#include <stdio.h>#include<stdlib.h>typedef struct lnode{ int data; lnode *next;}lnode;lnode* initial(){ lnode *head; head = (lnode *)malloc(sizeof(lnode)); head->.原创 2021-03-22 10:22:13 · 113 阅读 · 0 评论 -
sdut oj 顺序表应用6:有序顺序表查询
#include<stdio.h>#include<stdlib.h>typedef struct{ int data[100010]; int length;}sqlist;void initial(sqlist &l,int n){ l.length=n;}void create(sqlist &l){ int i; for(i=1;i<=l.length;i++) scanf("%d".原创 2021-03-14 11:30:12 · 86 阅读 · 0 评论 -
sdut oj 顺序表应用1:多余元素删除之移位算法
AC#include<stdio.h>#include<stdlib.h>typedef struct{ int data[100010]; int length;}sqlist;void initial(sqlist &l,int n){ l.length=n;}void create(sqlist &l){ int i; for(i=1;i<=l.length;i++) scanf(原创 2021-03-14 16:34:41 · 92 阅读 · 0 评论 -
sdut oj 顺序表应用5:有序顺序表归并
#include <stdio.h>#include <stdlib.h>typedef struct{ int data[10020]; int length;}sqlist;void initial(sqlist &l,int n){ l.length=n;}void together(sqlist a,sqlist b,sqlist &c){ int i=1,j=1,t=1,q=0; while(i<.原创 2021-03-12 21:30:39 · 89 阅读 · 0 评论 -
sdut oj 数据结构实验之链表四:有序链表的归并
AC注:第一次RTE 不熟练需要多敲几次#include <iostream>using namespace std;#include <stdio.h>#include<stdlib.h>typedef struct lnode{ int data; lnode *next;}lnode;lnode* initial(){ lnode *head; head=(lnode *)malloc(sizeof(lno.原创 2021-03-22 11:35:41 · 119 阅读 · 0 评论 -
数据结构实验之链表六:有序链表的建立
AC#include <iostream>using namespace std;#include <stdio.h>#include<stdlib.h>typedef struct lnode{ int data; lnode *next;}lnode;lnode* initial(){ lnode *head; head=(lnode *)malloc(sizeof(lnode)); head->n.原创 2021-03-24 15:38:21 · 127 阅读 · 0 评论 -
sdut oj 数据结构实验之栈与队列六:下一较大值(二)
AC思路:建立一个数组a[i]存输入数,再建立一个数组b[i]存a[i]的下一个最大值 维护一个单调递增栈 让a[i]倒序读入,此时栈空,第一个元素下一个最大值必为-1;若栈内元素比他大,说明为他的下一个最大值,存入b[i]中,然后a[i]压栈; 若栈内元素比他大或等于他,则栈内元素出栈,直至到达比他大的数,若没有,则为-1,若有,存入b[i]中,然后a[i]压栈;问题:1. 当数据量超过1e5的时候,不用cin cout,会超时!!!2. 建立一个数组a[i]存输入数,再建原创 2021-04-01 21:27:59 · 148 阅读 · 0 评论 -
sdut oj 栈和队列之我成了瘸腿鹅
思路 :数组模拟栈,每输入一个数都与栈中所有元素进行比较,若有的话则从数字相同的地方开始全部出栈,并且累加得分,根据%2是否为0来区分两个人,否则入栈注意:得的分数需要累加,要用+=,第一次wa因为忘了累加AC#include <iostream>#include<cstdlib>#include<cstdio>using namespace std;int main(){ int n,top=0,x=0,y=0,flag,i..原创 2021-04-10 13:58:05 · 917 阅读 · 0 评论 -
sdut oj 数据结构实验之栈与队列一:进制转换
AC注意:1. 若输入为0,则需单独判断,因为0的任何进制位数都是0;2. 用到大进制数转小进制数:被转换数÷进制,余数进栈#include <iostream>using namespace std;#include <stdio.h>#include<stdlib.h>#define N 1000typedef struct{ int data[N]; int top;}sqstack;void initsqst..原创 2021-03-25 17:00:34 · 148 阅读 · 0 评论 -
sdut oj 数据结构实验之栈与队列八:栈的基本操作
AC问题:每个输出占据一行,每组测试数据(最后一组除外)完成后,输出一个空行。实现:while(t--){……if(t) cout<<endl;}#include<stdio.h>#include<stdlib.h>#include<iostream>#include<stack>using namespace std;int s[100005];int main(){ int t,..原创 2021-03-31 15:15:47 · 115 阅读 · 0 评论 -
sdut oj 数据结构实验之栈与队列二:一般算术表达式转换成后缀式
1. STL中stack的使用:stack<int> s; //stack关键字和<int>之间不能有空格#include <string>#include <stack>#include<iostream>using namespace std;stack<char> s;void juge(char x){ if(s.empty()) s.push(x); else if(x=='(') .原创 2021-03-29 11:23:18 · 79 阅读 · 0 评论 -
sdut oj 数据结构实验之栈与队列四:括号匹配
#include <string>#include <stack>#include<iostream>using namespace std;int main(){ string p; cin>>p; stack<char> s; int flag=0,i; for(i=0; i<p.length(); i++) { if(f.原创 2021-03-30 21:00:49 · 131 阅读 · 0 评论 -
队列:循环队列基本操作
目录一、简介1.循环队列的用处2.基本操作3.注意二、代码实现1. 队列创建2. 队列初始化3.判空4. 压入队列5.出队列6.取队头元素7.取队尾元素一、简介1.循环队列的用处采用求余方式实现元素的循环存储,避免假溢出现象2.基本操作若rear+1,则对其与N(队列最大容量数)求余,即rear=(rear+1)%N 若front+1,则对其与N(队列最大容量数)求余,即front=(front+1)%N 若rea...原创 2021-04-07 21:08:53 · 3088 阅读 · 0 评论 -
数据结构之栈的函数
#include <iostream>using namespace std;#include <stdio.h>#include<stdlib.h>#define N 1000//创建顺序栈typedef struct{ int data[100]; int top;}sqstack;//初始化顺序栈void initsqstack(sqstack &s){ s.top=0;}//入栈void push(.原创 2021-03-25 16:32:07 · 3904 阅读 · 0 评论 -
sdut oj 数据结构实验之栈与队列十一:refresh的停车场
#include <iostream>#include <cstdio>#include<stack>#include<queue>#include<string>using namespace std;int main(){ int m,n; string order,number; while(scanf("%d %d",&n,&m)!=EOF){ stack<string> .原创 2021-04-03 09:05:37 · 142 阅读 · 0 评论 -
sdut oj 数据结构实验之栈与队列九:行编辑器
AC第一次wa是因为没读懂题目说的行首输入#的意思,如果行首输入了#直接忽略,而不入栈#include<stdio.h>#include<stdlib.h>#include<iostream>#include<stack>using namespace std;int s[100005];int main(){ string p; while(getline(cin,p)){ stack<c.原创 2021-03-31 14:50:45 · 137 阅读 · 0 评论 -
图的存储结构 概述
邻接矩阵#include<bits/stdc++.h>using namespace std;const int N = 1010;const int M = 2010;int a[N][N];int n,m;int main(){ int i,j; cin>>n>>m; //n个点 m条边 int u,v,w; memset(a,0x3f,sizeof a); //初始化数组,理解为每个点之间都没有边 .原创 2021-05-27 11:29:28 · 68 阅读 · 0 评论 -
2021-06-09
#include<bits/stdc++.h>using namespace std;int n,m,s,d;const int N=1010;const int M=10010;int mp[N][N];int dis[N];int vis[N];//标记是否已经求得该点的最短路int i,j;void dij(int s){ //s为起点 memset(dis,0x3f,sizeof dis); for(int i=1;i<=n;i++){ .原创 2021-06-09 17:50:00 · 95 阅读 · 0 评论 -
2021-06-09
#include<bits/stdc++.h>using namespace std;int n,m,s,d;const int N=1010;const int M=10010;int mp[N][N];int dis[N];int vis[N];//标记是否已经求得该点的最短路int i,j;typedef pair<int,int> PII;//头文件queuevoid dij(int s){ //s为起点 memset(dis,0x3f,s.原创 2021-06-09 18:04:45 · 70 阅读 · 0 评论 -
sdut oj 数据结构实验之二叉树八:(中序后序)求二叉树的深度
AC#include <iostream>#include<cstdio>#include<cstdlib>#include<string.h>using namespace std;typedef struct bitnode{ char data; struct bitnode *lch,*rch;}bitnode,*bitree;int i=0;char post[500],in[500];bitree cr.原创 2021-04-23 01:37:05 · 131 阅读 · 0 评论 -
树
#include <iostream>using namespace std;#include<cstdio>int c=0; //叶子数//树结点的存储结构(类似链表)typedef struct bitnode{ int data; struct bitnode *lch,*rch;}bitnode,*bitree;//先序遍历void preorder(bitree t){ if(t){ printf(t->.原创 2021-04-22 19:44:52 · 58 阅读 · 0 评论 -
二叉树的先序和中序遍历(非递归)
一. 二叉树的先序遍历#include <iostream>#include<cstdio>#include<cstdlib>#include<stack>using namespace std;typedef struct bitnode{ char data; struct bitnode *lch,*rch;}bitnode,*bitree;stack<bitree> s;int i=0;char原创 2021-04-22 20:16:12 · 104 阅读 · 0 评论 -
二叉树基本操作(oj)
AC二叉树基本操作:先中后顺序遍历,层序遍历,叶子数,层数#include <iostream>#include<cstdio>#include<cstdlib>#include<stack>#include<queue>using namespace std;typedef struct bitnode{ char data; struct bitnode *lch,*rch;}bitnode,*bitr原创 2021-04-22 21:27:41 · 263 阅读 · 0 评论 -
sdut oj 数据结构实验之二叉树五:层序遍历
AC#include <iostream>#include<cstdio>#include<cstdlib>#include<stack>#include<queue>using namespace std;typedef struct bitnode{ char data; struct bitnode *lch,*rch;}bitnode,*bitree;queue<bitree> q;.原创 2021-04-22 20:33:35 · 107 阅读 · 0 评论 -
sdut oj 数据结构实验之二叉树四:(先序中序)还原二叉树
AC#include <iostream>#include<cstdio>#include<cstdlib>#include<stack>#include<queue>using namespace std;int n;typedef struct bitnode{ char data; struct bitnode *lch,*rch;}bitnode,*bitree;int i=0;char pre.原创 2021-04-23 01:40:02 · 113 阅读 · 0 评论 -
迷宫
#include <iostream>#include <cstdio>#include<string>using namespace std;int n,m,c;int maze[10][10],state[10][10];int dx[4]={1,0,-1,0};int dy[4]={0,1,0,-1};void dfs(int x,int y){ if(x==n&&y==m) { c++;return; .原创 2021-04-07 11:32:04 · 79 阅读 · 0 评论 -
STL工具之vector的使用
vector的使用方法:1)vector<int>a定义一个int类型的vector一维数组。(2)vector<int>a(10)定义一个int类型的长度为十的vector一维数组。(3)vector<int>a(10)(1)定义一个int类型的长度为十初值为一的vector一维数组。(4)vector<vector<int>>a定义一个int类型的vector二维数组,要注意的是,在里面的vecotr<...原创 2021-03-25 21:45:05 · 372 阅读 · 0 评论 -
2021-03-25 第四周周四小节and错误梳理
1. 链表的定义由于结构体是递归调用,故在调用next指针时要写struct lnode,表示这是你正在定义的结构体typedef struct lnode{ int data; struct lnode* next;}lnode;2. 栈2.1. 栈的判断是否为空函数:int Empty(sqstack &s){ if(s.top==0) return 1; else return 0;}若为空,返回1,否则返回0;2.2..原创 2021-03-25 21:42:47 · 84 阅读 · 0 评论