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

最后

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

❤️ 谢谢支持,喜欢的话别忘了 关注、点赞哦。

前端校招面试题精编解析大全

p->right=NULL;//新节点要作为叶子结点插入
p->left=NULL;
if(root==NULL)
{
	root=p;
	return p;
}
q=root;
while(flag==0)//标志完成插入
{
	if(q->key>x)
	{
		if(q->left!=NULL)
			q=q->left;
		else
		{
			q->left=p;//在左子数插入
			flag=1;
		}
	}
	else
	{
		if(q->right!=NULL)
			q=q->right;
		else
		{
			q->right=p;//在右子树插入
			flag=1;
		}
	}
}
return root;

}
void Inorder(struct Bnode *BD)
{
if(BD!=NULL)
{
Inorder(BD->left);
printf(“%5d”, BD->key);
Inorder(BD->right);
}

}
void main()
{
int i,length;
int a[MAX];
Bnode *root=NULL;
printf(“输入数组大小:”);
scanf(“%d”,&length);
for(i=0;i<length;i++)
{
scanf(“%d”,&a[i]);
root=btlnsert(a[i],root);
}
printf(“输出所给排序为:\n”);
Inorder(root);
}


## 3、二叉树层次遍历.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 Inorder(struct BTreeNode *BT)
{
if(BT!=NULL)
{
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;

最后前端到底应该怎么学才好?

如果你打算靠自己摸索自学,那么你首先要了解学习前端的基本大纲,这是你将要学习的主要内容,理解以及掌握好这些内容,便可以找到一份初级的前端开发工作。你还需要有一套完整的前端学习教程,作为初学者最好的方式就是看视频教程学习,初学者容易理解接受。

不要选择买书学习,这样的方式没有几个人能学会,基本都是看不下去书,也看不懂书。如果喜欢看书的学弟,可以买一些经典的书籍作为辅助即可,主要还是以看教程为主。每天抽出固定几个小时学习,做好长期学习的准备。学习编程并不是每天光看视频,你学习编程最重要的目的是为了编写软件产品,提供给大众使用,所以用手写出代码实现功能才是我们要做的事情。

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

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

ZG4ubmV0L3h6aXQ0OTQ4MDE4MzE=,size_16,color_FFFFFF,t_70#pic_center)

在这里插入图片描述

在这里插入图片描述

  • 19
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值