ITeye博客

C++

共 2 篇文章

排序算法C++

#include #include using namespace std; #define MAXSIZE 30 typedef struct { int key; string name; }RedType; typedef struct SqList { RedType r [MAXSIZE+1]; int length; }SqList; //插入排序 /////////////////////////////////////////////////////////////////// //直接插入排序 时间复杂度O(n2) //r[0]处设为哨兵 void insertSort(S…

2012-09-16 16:49 · C++ · C++

汉诺塔C++

int c = 0; void move(char x, int n, char z) { cout<<++c <<"," <<"第"<<n<<"个,从" <<x <<",移动到"<<z <<endl; } void Hanoi(int n, char A, char B, char C) { //当n=1时,直接移动到C if (n == 1) { move(A, 1, C); } else { //将前n-1个,从A通过C,移动到B Hanoi(n-1, A, C, B); //将最后一个移动到C move(A, n, C); //将前n-1个,从B通过A,移动到C Hanoi(n-1,…

2012-09-15 20:46 · C++ · C++