ZKX's LAB

数据结构相关编程题 3道数据结构编程题~~~

2021-04-28知识2

《数据结构》编程题 二叉树以二叉链表表示,利用递归思想求一棵二叉树中叶子结点的总数二叉树的链表递归实现*/btree createbtree(int*data,int pos){btree newnode;if(data[pos]=0|pos>;15)return NULL;else{newnode=(btree)malloc(sizeof(treenode));newnode->;data=data[pos];newnode->;left=createbtree(data,2*pos);newnode->;right=createbtree(data,2*pos+1);return newnode;}}二叉树的中序输出*/void printbtree(btree ptr){if(ptr。NULL){printbtree(ptr->;left);printf(\"[%2d]\",ptr->;data);ptintbtree(ptr->;ritght);}}

数据结构编程题 对于基本有序的序列,用折半查找。

一个数据结构的编程题 /敢死队问题,使用单向循环链表includeusing namespace std;typedef struct node{int num;node*next;}lnode;定义结点typedef struct{lnode*cl;}linklist;void main(){int M;int i;int start,count;linklist l;cout;cin>;>;M;for(start=1;start;start+)/start为测试起点{初始化链表lnode*p=new lnode;l.cl=p;l.cl->;num=1;for(i=2;i;i+){lnode*q=new lnode;q->;num=i;p->;next=q;p=q;}lnode*t=new lnode;t->;num=M;p->;next=t;p=t;t->;next=l.cl;找到起点p=l.cl;for(i=1;i;i+){p=p->;next;}count=0;while(count){for(i=1;i;i+){t=p;p=t->;next;}t->;next=p->;next;count+;p=t->;next;}if(p->;num=1)break;}cout;}敢死队问题,使用循环队列includeusing namespace std;define QueueSize 100/假定预分配的队列空间最多为100个元素typedef int DataType;假定队列元素的数据类型为字符typedef struct{int data[QueueSize];int front;头指针int rear;尾指针int count;计数器,记录队中元素总数}CirQueue;置队列空void Initial(CirQueue*Q){/将顺序队列置空Q->;front=Q->;rear=0;Q->;count=0;计数器置0}判队列空int IsEmpty(CirQueue*Q){return Q->;。

#七酱编程达人数据结构#数据结构编程技术有哪些#编程之数据结构#编程数据结构第四讲#名师带你学编程之数据结构

qrcode
访问手机版