2014年3月10日

快速排序与二分查找

摘要: // BinarySearch.cpp : Defines the entry point for the console application.//#include "stdafx.h"/*/处理两数交换*/void swap(int& a, int& b){ int temp = a; a = b; b = temp;}//在数组a中,排序区间为[low, high]int partition(int a[],int low, int high){ int temp = a[high];//temp为基准值 int middle = low; ... 阅读全文

posted @ 2014-03-10 23:43 欧阳君 阅读(373) 评论(0) 推荐(0)

2014年3月5日

汉诺塔问题

摘要: // Hanoi.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include int count = 0; //全局变量,保存移动次数/*汉诺塔问题,将n个盘子从A移动至C,借助C,输出移动方式和移动次数*/void Hanoi(int n, char A, char B, char C){ if(n == 1) { printf("Move %c ----> %c \n", A, C); count++; return; ... 阅读全文

posted @ 2014-03-05 10:03 欧阳君 阅读(89) 评论(0) 推荐(0)

荷兰国旗问题

摘要: // FlagArrange.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include /*由红白蓝三种颜色的球组成的序列,编写算法,使得该序列排列次序为红球,白球,蓝球,且时间复杂度为O(n);思路:假设红白蓝三种颜色依次用数字1,2,3来表示,则问题变为:12223311123122221111113333,将这些随机序列变为111111122222333*/void swap(int &a, int &b){ int temp = a; 阅读全文

posted @ 2014-03-05 10:01 欧阳君 阅读(145) 评论(0) 推荐(0)

导航