【アルゴリズム】インクリメントシーケンス

1855 ワード

n個の整数シーケンスが与えられ、そのシーケンスの1つの配列が出力され、a 1’<=a 2’<=......<=an’.
 
問題解決の考え方:
//              ,             
#include
#include
#include
using namespace std;

void Display(int a[],int n);
void Display(int a[],int n){
	for(int i=0;ix){
			for(int y=j;y<=r;y++)
				b[k++]=a[y];
		}
		else if(j>r){
			for(int y=i;y<=x;y++)
				b[k++]=a[y];
		}
	}
}
void Copy(int a[],int b[],int left,int right){
	if(left<=right){
		for(int i=left;i<=right;i++)
			a[i]=b[i];
	}
}
//   
void MergeSort2(int a[],int n);
void MergePass(int a[],int b[],int s,int n);

void MergeSort2(int a[],int n){
	int *b=new int[n];
	int s=1;
	while(sx) ;
		if(i>=j)
			break;
		Swap(a[i],a[j]);
	}
	a[p]=a[j];
	a[j]=x;
	return j;
}

void Swap(int &x,int &y){
	int a=x;
	x=y;
	y=a;
}
//   
int RandPartition(int a[],int p,int r);
void RandQuickSort(int a[],int p,int r);
int Random(int x,int y);

int Random(int x,int y){
	int i=x,j=y;
	int temp=rand()%(j-i+1)+i;
	return temp;
	
}
int RandPartition(int a[],int p,int r){
	int i=Random(p,r);
	Swap(a[i],a[p]);
	return Partition(a,p,r);
}
void RandQuickSort(int a[],int p,int r){
	if(p>n;
	for(int i=0;i>a[i];
	int b[100],c[100],d[100];
	for(int i=0;i