llllmz

导航

2024年1月24日

KY124 二叉搜索树C++

摘要: 先把BST建立起,然后递归遍历判断树就好了。 #include<iostream> #include<string> using namespace std; struct node{ char data; struct node* left; struct node* right; }; type 阅读全文

posted @ 2024-01-24 21:19 神奇的萝卜丝 阅读(32) 评论(0) 推荐(0)

KY207 二叉排序树C++

摘要: 考二叉搜索树的插入。 #include<iostream> using namespace std; struct node{ int data; struct node* left; struct node* right; }; typedef struct node tree; int main 阅读全文

posted @ 2024-01-24 20:54 神奇的萝卜丝 阅读(15) 评论(0) 推荐(0)

KY11 二叉树遍历C++

摘要: 这个题目思路其实就是先序遍历的变形。 相当于沿着先序遍历的顺序跟着构建二叉树就行。然后中序遍历这个树。 #include<iostream> #include<string> using namespace std; struct tnode{ char data; struct tnode* le 阅读全文

posted @ 2024-01-24 20:29 神奇的萝卜丝 阅读(20) 评论(0) 推荐(0)

KY212 二叉树遍历C++

摘要: 思路是先构造出树,然后在后序遍历整个树。 #include<iostream> #include<string> using namespace std; struct Tnode{ char data; struct Tnode* left; struct Tnode* right; }; typ 阅读全文

posted @ 2024-01-24 19:51 神奇的萝卜丝 阅读(24) 评论(0) 推荐(0)

2024年1月22日

KY85 二叉树C++

摘要: 递归判断当前节点和n的关系就好了。如果小于等于n那就是存在。 #include<iostream> using namespace std; int count(int i,int n){ if(i>n) return 0; return count(2*i,n)+ count(2*i+1,n)+1 阅读全文

posted @ 2024-01-22 20:16 神奇的萝卜丝 阅读(24) 评论(0) 推荐(0)

KY96 FibonacciC++

摘要: #include<iostream> using namespace std; int compute(int n){ if(n==1) return 1; if(n==0) return 0; return compute(n-1)+ compute(n-2); } int main(){ int 阅读全文

posted @ 2024-01-22 19:59 神奇的萝卜丝 阅读(15) 评论(0) 推荐(0)

4147:汉诺塔问题(Tower of Hanoi)C++

摘要: 递归C和C++一样,就写个C++了。 #include<iostream> using namespace std; void move(int n,char a,char b,char c){ if(n<=0) return; move(n-1,a,c,b); cout << n << ":"<< 阅读全文

posted @ 2024-01-22 17:05 神奇的萝卜丝 阅读(32) 评论(0) 推荐(0)

KY17 n的阶乘C++

摘要: 递归一下。 #include<iostream> using namespace std; long compute(int n){ if(n==1) return 1; return n* compute(n-1); } int main(){ int n; while( cin >> n){ c 阅读全文

posted @ 2024-01-22 15:58 神奇的萝卜丝 阅读(14) 评论(0) 推荐(0)

2024年1月18日

KY129 简单计算器C++

摘要: 、 这是目前阶段做的最难最吃力的题目。调试了一遍又一遍去看逻辑上出现的各种问题。。。 #include<iostream> #include<string> #include<stack> #include<map> using namespace std; int main(){ map<char 阅读全文

posted @ 2024-01-18 22:15 神奇的萝卜丝 阅读(31) 评论(0) 推荐(0)

1978:扩号匹配问题C

摘要: #include<stdio.h> int main(){ char s[101]; while(scanf("%s",s)!=EOF){ printf("%s\n",s); char tem[101]; int a[101]={0}; int top=0; int i=0; for(;s[i]!= 阅读全文

posted @ 2024-01-18 19:29 神奇的萝卜丝 阅读(21) 评论(0) 推荐(0)