摘要:已知二叉树的中序和前序求后序已知:中序:dgbaechf 前序:adbgcefh思路:前序遍历的第一个元素是根节点a,然后查找中序中a的位置,把中序遍历分为 dgb a echf,而因为节点个数要对应,则把前序遍历分为a dbg cefh,dbg为左子树,cefh为右子树,即可递归下去。 1 #include 2 #include 3 #include 4 5 // 二叉树节点结构 6 typedef struct bitnode 7 { 8 char data; // 节点存储的数据 9 struct bitnode *lchi...
        
阅读全文
 
    
        
        
摘要:流程练习题,基本不涉及什么算法。要求:学生有(学号,姓名,性别,年龄),初始化三个学生的信息(10,wes,f,23)(20,ert,f,45)(30,str,t,89),然后对学生信息进行插入和删除处理例如I12,rt,f,67表示插入12,rt,f,67D10 表示删除学号为10的学生的信息每次操作完成以后输出所有学生的信息按学号从小到大排序输入:I12,rt,f,67输出(10,wes,f,23) (12,rt,f,67) (20,ert,f,45) (30,str,t,89)输入:D10输出(12,rt,f,67) (20,ert,f,45) (30,str,t,89) 1 #incl
        
阅读全文
 
    
        
        
摘要:递归练习题(一)输入 n 值, 使用递归函数,求杨辉三角形中各个位置上的值,按照如下形式打印输出图形。例如:当 n=6 时。 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 #include 2 3 // 递归求杨辉三角形 4 int YHtrangle(int row,int col) 5 { 6 if (col == 0 || col == row){ 7 return 1; 8 } 9 else{10 return YHtrangle(row-1,col-1)+YHtrangle(ro...
        
阅读全文
 
    
        
        
摘要:从键盘上任意输入一个长度不超过 20 的字符串,对所输入的字符串,按照 ASCII 码的大小从小到大进行排序,请输出排序后的结果。 1 // 算法一 2 #include 3 #include 4 #include 5 using namespace std; 6 void main() 7 { 8 string s; 9 cout>s;11 sort(s.begin(),s.end());12 cout 3 #include 4 #include 5 int cmp(const void *a,const void *b) 6 { 7 return...
        
阅读全文
 
    
        
        
摘要:N 个人围成一圈顺序编号,从 1 号开始按 1、2、3 顺序报数,报 3 者退出圈外,其余的人再从 1、2、3 开始报数,报 3 的人再退出圈外,依次类推。请按退出顺序输出每个退出人的原序号。要求使用环行链表编程。 1 #include 2 #include 3 4 // 链表节点 5 typedef struct node 6 { 7 int num; 8 struct node *next; 9 }LNode;10 11 int main()12 {13 int n,i;14 printf("Please input number of peop...
        
阅读全文
 
    
        
        
摘要:从键盘输入 4 个学生的数据( 包括姓名、年龄和成绩),并存放在文件 sf1 上。从该文件读出这些数据,按成绩从高到底排序,并输出所有数据。 1 #include 2 3 // 定义学生信息结构 4 struct stu 5 { 6 char name[100]; 7 int age; 8 int res; 9 };10 11 int main()12 {13 struct stu stu[4];14 struct stu fstu[4];15 struct stu tmp;16 FILE *fwrt,*fred;17 int...
        
阅读全文