10个数据结构课程设计例子(C语言完整源码)二叉排序树、快速排序、冒泡排序、二叉树非递归遍历(3)

总结

我在成长过程中也是一路摸爬滚打,没有任何人的指点,所以走的很艰难。例如在大三的时候,如果有个学长可以阶段性的指点一二,如果有已经工作的师兄可以告诉我工作上需要什么,我应该前面的三年可以缩短一半;后来去面试bat,失败了有5、6次,每次也不知道具体是什么原因,都是靠面试回忆去猜测可能是哪方面的问题,回来学习和完善,当你真正去招人的时候,你就会知道面试记录是多么重要,面试官可以从面试记录里看到你的成长,总是去面试,总是没有成长,就会被定义为缺乏潜力。

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

image
image

{	
	Inorder(BT->lchild);
	printf("%5c", BT->date);
	Inorder(BT->rchild);
}

}
void levelerder(struct BTreeNode *BT )
{
struct BTreeNode *q[MS];
int front=0,rear=0;
if(BT!=NULL)
{
rear=(rear+1)%MS;
q[rear]=BT;
}
while(front!=rear)
{
struct BTreeNode *p;
front=(front+1)%MS;
p=q[front];
printf(“%5c”,p->date);
if(p->lchild!=NULL)
{
rear=(rear+1)%MS;
q[rear]=p->lchild;
}
if(p->rchild!=NULL)
{
rear=(rear+1)%MS;
q[rear]=p->rchild;
}
}
}
void main()
{
TNODE *t;
int a;
printf(“input the number of BTreeNode\n”);
scanf(“%d”,&a);
t=creat(a);
Inorder(t);
levelerder(t);
}


## 4、二叉树非递归遍历.c



/***********************************************************
我的信息: *
编程ID
***********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define MS 50
struct BTreeNode
{
char date;
struct BTreeNode *lchild;
struct BTreeNode *rchild;
};
typedef struct BTreeNode TNODE;
TNODE *creat(int n)
{
int i,j;
char x;
TNODE *narr[100],*p,*t;
for(j=1;j<=n;j++)
{
printf(“input i,x:\n”);
scanf(“%d,%c”,&i,&x);
p=(TNODE*)malloc(sizeof(TNODE));
p->date=x;
p->lchild=NULL;
p->rchild=NULL;
narr[i]=p;
if(i1)
t=p;
else
{
if(i%2
0)
narr[i/2]->lchild=p;
else
narr[i/2]->rchild=p;
}
}
return(t);
}
void Preorder(struct BTreeNode *BT)
{
if(BT!=NULL)
{
printf(“%5c”, BT->date);
Preorder(BT->lchild);
Preorder(BT->rchild);
}

}
void Inorder(struct BTreeNode *BT)
{
if(BT!=NULL)
{
Inorder(BT->lchild);
printf(“%5c”, BT->date);
Inorder(BT->rchild);
}

}
void Postorder(struct BTreeNode *BT)
{
if(BT!=NULL)
{
Postorder(BT->lchild);
Postorder(BT->rchild);
printf(“%5c”, BT->date);
}

}
void PreorderN(struct BTreeNode *BT)
{
struct BTreeNode *s[20];
int top=-1;
struct BTreeNode *p=BT;
while(top!=-1||p!=NULL)
{
while(p!=NULL)
{
top++;
s[top]=p;
printf(“%5c”,p->date);
p=p->lchild;
}
if(top!=-1)
{
p=s[top];
top–;
p=p->rchild;
}
}
}
void InorderN(struct BTreeNode *BT)
{
struct BTreeNode *s[20];
int top=-1;
struct BTreeNode *p=BT;
while(top!=-1||p!=NULL)
{
while(p!=NULL)
{
top++;
s[top]=p;
p=p->lchild;

	}
	if(top!=-1)
	{
		p=s[top];
		top--;
		printf("%5c",p->date);
		p=p->rchild;
	}
}

}
void PostorderN(struct BTreeNode *BT)
{
struct BTreeNode *s[20];
int top=-1,flag=1;
struct BTreeNode *p=BT,*q;
do{
while(p!=NULL)
{
top++;
s[top]=p;
p=p->lchild;
}

	q=NULL;
	flag=1;
		while(top!=-1&&flag)
		{
			p=s[top];	
			if(p->rchild==q)
			{
				printf("%5c",p->date);	          
				top--;
				q=p;
			}
			else
			{
			    p=p->rchild;	
				flag=0;
			}	
		}
}while(top!=-1);

}
void main()
{
TNODE *t;
int a;
printf(“input the number of BTreeNode\n”);
scanf(“%d”,&a);
t=creat(a);
printf(“中序遍历:”);
Inorder(t);
printf(“\n”);
InorderN(t);
printf(“\n”);
printf(“先序遍历:”);
Preorder(t);
printf(“\n”);
PreorderN(t);
printf(“\n”);
printf(“后序遍历:”);
Postorder(t);
printf(“\n”);
PostorderN(t);
printf(“\n”);
}


## 5、二叉树建立.c



/***********************************************************
我的信息: *
编程ID
***********************************************************/
void preorder1(bitree *root)
{
bitree *p,*s[100];
int top=0;
p=root;
while((p!=NULL)||(top>0))
{
while(p!=NULL)
(cout<data<<" “;
s[++top]=p;//
p=p->lchild;
}
p=s[top–];
p=p->rchild;
}
}
void inorder1(bitree *root)
{
bitree *p,*s[100];
int top=0;
p=root;
while((p!=NULL)||(top>0))
{
while(p!=NULL)
{
s[++top]=p;p=p->lchild;
}
{
p=s[top–];
cout<data<<”“;
p=p->rchild;
}
}
}
void postorder1(bitree *root)
{
bitree *p,*s1[100];
ints2[100],top=0,b;
p=root;
do
{
while(p!=NULL)
{
s1[top]=p;s2[top++]=0;
p=p->lchild;
}
if(top>0)
{
b=s2[–top];
p=s1[top];
if(b==0)
{
s1[top]=p;
s2[top++]=1;
p=p->rchild;
}
else
{
cout<data<<” ";
p=NULL;
}
}
}while(top>0);
}
void main()
{
bitree *root;
root=create();
cout<<“先序遍历的结果”<<endl;
preorder1(root);cout<<end1;
cout<<“中序遍历的结果”<<end1;
inorder1(root);cout<<end1;
cout<<“后序遍历的结果”<<end1;
postorder1(root);cout<<end1;
}


## 6、快速排序.c



/***********************************************************
我的信息: *
编程ID
***********************************************************/
#include<stdio.h>
void quicksort(int a[],int start,int end)
{
int i,j;
int mid;
if(start>=end)
return;
i=start;
j=end;
mid=a[i];
while(i<j)
{
while(i<j&&a[j]>mid)
j–;
if(i<j)
{
a[i]=a[j];
i++;
}
while(i<j&&a[i]<=mid)
i++;
if(i<j)
{
a[j]=a[i];
j–;
}
}
a[i]=mid;
quicksort(a,start,i-1);
quicksort(a,i+1,end);
}
void scan(int a[],int n)
{
int i;
for(i=1;i<=n;i++)
{
scanf(“%d”,&a[i]);
}
}
void print(int a[],int n)
{
int i;
for(i=1;i<=n;i++)
{
printf(“%5d”,a[i]);
}
}
void main()
{
int a[1000];
int s;
int start=1,end;
printf(“输入数组长度:”);
scanf(“%d”,&s);
end=s;
scan(a,s);
quicksort(a,start,end);
print(a,s);
}


## 7、括号匹配.c



/***********************************************************
我的信息: *
编程ID
***********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
struct node
{
char date;
struct node *next;
};
struct node *top;
void push (char x)
{
struct node *p;
p=(struct node *)malloc(sizeof(struct node));
p->date=x;
p->next=top;
top=p;
}
char pop()
{
struct node *p;
char x;
if (topNULL)
printf(“栈下溢错误!\n”);
p=top;
x=p->date;
top=top->next;
free§;
return(x);
}
void main()
{
char x,y;
printf(“括号匹配,请输入括号:\n”);
scanf(“%c”,&x);
while(x!=‘\n’)
{
if(x
’(‘||x==’[‘||x==’{‘)
{
push(x);
scanf(“%c”,&x);
}
if(x==’)‘||x==’]‘||x==’}‘)
{
if (topNULL)
{
printf(“不匹配!\n”);
exit(1);
}
y=pop();
if((y
’(‘&&x==’)‘)||(y==’[‘&&x==’]‘)||(y==’{‘&&x==’}'))
{
scanf(“%c”,&x);
}
else
{
printf(“不匹配!\n”);
exit(0);
}
}

}
if (top!=NULL)
{
	printf("不匹配!\n");
	exit(1);
}
printf("括号匹配成功!\n");

}


## 8、冒泡排序.c



/***********************************************************
我的信息: *
编程ID
***********************************************************/
#include<stdio.h>
void bsort(int a[],int n)
{
int temp;
int i,j,flag;
for(j=1;j<=n-1;j++)
{
flag=0;
for(i=1;i<=n-j;i++)
if(a[i]>a[i+1])
{
flag=1;
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
if(flag==0)break;
}
}
void scan(int a[],int n)
{
int i;
for(i=1;i<=n;i++)
{
scanf(“%d”,&a[i]);
}
}
void print(int a[],int n)
{
int i;
for(i=1;i<=n;i++)
{
printf(“%5d”,a[i]);
}
}
void main()
{
int a[1000];
int s;
printf(“输入数组长度:”);
scanf(“%d”,&s);
scan(a,s);
bsort(a,s);

Vue 面试题

1.Vue 双向绑定原理
2.描述下 vue 从初始化页面–修改数据–刷新页面 UI 的过程?
3.你是如何理解 Vue 的响应式系统的?
4.虚拟 DOM 实现原理
5.既然 Vue 通过数据劫持可以精准探测数据变化,为什么还需要虚拟 DOM 进行 diff 检测差异?
6.Vue 中 key 值的作用?
7.Vue 的生命周期
8.Vue 组件间通信有哪些方式?
9.watch、methods 和 computed 的区别?
10.vue 中怎么重置 data?
11.组件中写 name 选项有什么作用?
12.vue-router 有哪些钩子函数?
13.route 和 router 的区别是什么?
14.说一下 Vue 和 React 的认识,做一个简单的对比
15.Vue 的 nextTick 的原理是什么?
16.Vuex 有哪几种属性?
17.vue 首屏加载优化
18.Vue 3.0 有没有过了解?
19.vue-cli 替我们做了哪些工作?

如果你觉得对你有帮助,可以戳这里获取:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

?
4.虚拟 DOM 实现原理
5.既然 Vue 通过数据劫持可以精准探测数据变化,为什么还需要虚拟 DOM 进行 diff 检测差异?
6.Vue 中 key 值的作用?
7.Vue 的生命周期
8.Vue 组件间通信有哪些方式?
9.watch、methods 和 computed 的区别?
10.vue 中怎么重置 data?
11.组件中写 name 选项有什么作用?
12.vue-router 有哪些钩子函数?
13.route 和 router 的区别是什么?
14.说一下 Vue 和 React 的认识,做一个简单的对比
15.Vue 的 nextTick 的原理是什么?
16.Vuex 有哪几种属性?
17.vue 首屏加载优化
18.Vue 3.0 有没有过了解?
19.vue-cli 替我们做了哪些工作?
[外链图片转存中…(img-YiMMunEn-1715334684396)]

如果你觉得对你有帮助,可以戳这里获取:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

  • 16
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,让我来简单介绍一下二叉排序树的概念和实现思路。 二叉排序树又称为二叉搜索树,是一种特殊的二叉树,它满足以下条件: 1. 对于任意结点,它的左子树中的所有结点的值都小于它的值; 2. 对于任意结点,它的右子树中的所有结点的值都大于它的值; 3. 左右子树都是二叉排序树。 根据这个定义,我们可以用二叉链表来实现一棵二叉排序树。具体实现思路如下: 1. 定义二叉树的结点类型,包括结点的值、左右子结点指针; 2. 定义一个函数,用于向二叉排序树中插入一个结点; 3. 读入一组序列,依次插入到二叉排序树中; 4. 中序遍历整棵二叉排序树,输出结点的值。 下面是具体的代码实现,你可以参考一下: ```c #include <stdio.h> #include <stdlib.h> // 定义二叉树结点类型 typedef struct node { int value; struct node* left; struct node* right; } Node; // 向二叉排序树中插入一个结点 Node* insert(Node* root, int value) { if (root == NULL) { // 如果当前结点为空,就创建一个新的结点 Node* node = (Node*)malloc(sizeof(Node)); node->value = value; node->left = NULL; node->right = NULL; return node; } else if (value < root->value) { // 如果插入的值小于当前结点的值,就插入到左子树中 root->left = insert(root->left, value); } else { // 如果插入的值大于等于当前结点的值,就插入到右子树中 root->right = insert(root->right, value); } return root; } // 中序遍历二叉排序树 void inorder(Node* root) { if (root == NULL) { return; } inorder(root->left); printf("%d ", root->value); inorder(root->right); } int main() { // 读入一组序列,依次插入到二叉排序树中 int n, value; scanf("%d", &n); Node* root = NULL; for (int i = 0; i < n; i++) { scanf("%d", &value); root = insert(root, value); } // 中序遍历整棵二叉排序树,输出结点的值 inorder(root); return 0; } ``` 这样就完成了二叉排序树的建立和中序遍历。当然,这只是一个简单的实现,如果你想进一步了解二叉排序树的相关知识,可以参考一些经典的算法教材。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值