
----------数据结构----------
言寺之风雅颂
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
有序链表的建立
第一种,直接在输入数据的时候找到要插入的合适位置。 //版本1 #include "iostream" using namespace std; struct node { int data; struct node *next; }; int main() { int n; cin>>n; //总共有n个数 struct node *head, *p, *q, *r...原创 2019-04-24 21:32:59 · 2789 阅读 · 0 评论 -
双向链表
//双向链表,查找 key 的前驱和后继 #include "iostream" using namespace std; struct node { int data; struct node *before, *next; }; int main() { int n, key; cin >> n >> key; //n个数,要查找的数 key stru...原创 2019-05-08 21:13:08 · 158 阅读 · 0 评论 -
链表删除重复的元素
//链表删除重复的元素 #include <iostream> using namespace std; struct node { int data; struct node *next; }; //逆序建立链表 void createlist(struct node *L, int x) { struct node *p; p = (node*)malloc(siz...原创 2019-05-10 09:58:56 · 258 阅读 · 0 评论 -
约瑟夫问题(循环链表)
题目见另一篇博客: https://blog.youkuaiyun.com/macunshi/article/details/38499273 使用循环链表来做: #include "iostream" using namespace std; int n, m; struct node { int data; struct node *next; }; struct node *creat...原创 2019-05-10 10:19:25 · 297 阅读 · 0 评论 -
括号匹配问题(使用栈 和 模拟栈)
Problem Description 给你一串字符,可能包括括号、数字、字母、标点符号、空格,你的任务是检查这一串字符中的( ) ,[ ],{ }是否匹配。 Input 输入数据有多组,处理到文件结束。 Output 如果匹配就输出“yes”,不匹配输出“no” Sample Input sin(20+10) {[}] Sample Output yes no 使...原创 2019-05-15 10:17:34 · 261 阅读 · 0 评论 -
链表的逆置
//链表的就地逆置 #include "iostream" using namespace std; struct node { int data; struct node *next; }; int main() { int n; struct node *head,*p, *r, *q; head = (struct node *)malloc(sizeof(struct no...原创 2019-05-07 20:39:48 · 184 阅读 · 0 评论 -
十进制数转换任意进制(栈的应用)
//十进制数转任意进制 #include <iostream> #include <stack> using namespace std; void Ten2R(int n, int R) //将十进制数n转化为R进制的数 { stack<int>q; while (n != 0) { q.push(n%R); n /= R; } whil...原创 2019-05-17 11:07:52 · 732 阅读 · 0 评论 -
排队买饭(数组解法 和 模拟队列 和 双端队列 )
Problem Description 中午买饭的人特多,食堂真是太拥挤了,买个饭费劲,理工大的小孩还是很聪明的,直接奔政通超市,哈哈,确实,政通超市里面也卖饭,有好几种菜,做的比食堂好吃多了,价格也不比食堂贵,并且买菜就送豆浆,吸引了不少童鞋。所以有时吧,人还是很多的,排队是免不了的,悲剧的是超市只有两个收银窗口。 问题是这样的:开始有两队人在排队,现在咱们只研究第一队,现在我们给每个人一个...原创 2019-05-17 11:45:32 · 354 阅读 · 0 评论 -
1-n的全排列
#include <iostream> using namespace std; int a[100]; void dfs(int loc, int n) //loc所填的位置 { if (loc == n) //递归终止条件,填满了 { for (int i = 0; i<n; i++) cout << a[i] << " "; ...原创 2019-07-15 09:27:00 · 529 阅读 · 0 评论