摘要:8645归并排序(非递归算法)时间限制:1000MS 内存限制:1000K题型: 编程题语言: 无限制Description用函数实现归并排序(非递归算法),并输出每趟排序的结果Input第一行:键盘输入待排序关键的个数n第二行:输入n个待排序关键字,用空格分隔数据Output每行输出每趟排序的结果,数据之间用一个空格分隔Sample Input105 4 8 0 9 3 2 6 7 1Sample Output4 5 0 8 3 9 2 6 1 70 4 5 8 2 3 6 9 1 70 2 3 4 5 6 8 9 1 70 1 2 3 4 5 6 7 8 9//以下为AC代码#includ
阅读全文
摘要:二叉树的各种非递归遍历中,要数后序比较麻烦了,因为即使左子树为空,也不能马上出栈,而是要判断右子树。以下就给出代码:typedef struct Tnode{ ElemType data; struct Tnode *lchild,*rchild;}BBTnode,*BBTree;typedef struct{ BBTree *base,*top; //栈指针成员 int initsize; //栈初始长度 }Stack;//以下假设已经建好二叉树和栈了status NonFirstView(BBTree T,Stack S) //非递归前序遍历 { while(S.ba...
阅读全文
摘要:#include<iostream>#include<cstdlib>using namespace std;const int MAXSIZE = 100;const int OK = 1;const int ERROR = 0;typedef int status;typedef int ElemType;//平衡二叉排序树的结构typedef struct Tnode{ElemType data;struct Tnode *lchild,*rchild;int height; //以该节点为根的子树的高度}BBTnode,*BBTree;typedef BBTre
阅读全文
摘要:Description写一算法,删除单链性表中值相同的多余结点。即若链表中有多个结点具有相同的数据域值,只保留最后一个,其余结点均从链表中删去,使得最后得到的链表中的所有结点的数据域都不相同Input第一行 输入表长第二行 输入上一行指定的整数Output第一行 表中的数据第二行 处理后的表中的数据Sample Input125 3 1 4 1 9 8 9 5 7 6 2Sample Output5 3 1 4 1 9 8 9 5 7 6 23 4 1 8 9 5 7 6 2//代码如下#include<stdio.h>#include<stdlib.h>#define
阅读全文