2020011125 梁烁烁 2023.2.28

2020011125 梁烁烁 2023.2.28_第1张图片

概论 8 判断字符串是否为回文 

#include 
#include 
using namespace std;
bool Isopp(string str){
	int i = 0,j = str.length()-1;
	while(i>str;
	if(Isopp(str))
		cout<

概论 12 相差最小元素对个数(1)

#概论 12 相差最小元素对个数(1)
#include 
#include 
#include 
using namespace std;
int solve(vector &myv){
	sort(myv.begin(),myv.end());
	int ans = 1;
	int mindif = myv[1] - myv[0];
	for(int i = 2;i myv(a,a+n);
	cout<<"相差最小的元素对个数"<

概论 12 相差最小元素对个数其它排序算法

#概论 12 相差最小元素对个数其它排序算法 
#include
int Min(int a[],int n);
void BubbleSort(int a[],int n);
void InsertSort(int a[],int n);
void ShellSort(int a[], int n);
void swap(int a[],int low,int high);
int partition(int a[],int low,int high);
void quicksort(int a[],int low,int high);

int main(){
	int a[] = {9,8,1,3,2,4,5,0};
	int n = sizeof(a)/sizeof(a[0]);
//	BubbleSort(a,n);
//	InsertSort(a,n);
//	ShellSort(a,n);
	quicksort(a,0,n-1);
	printf("%d",Min(a,n));
	return 0;
	
} 

int Min(int a[],int n){
	int num = 1;
	int findmin = a[1] - a[0];
	for(int i = 2;ia[j]){
				int temp;
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
} 

void InsertSort(int a[],int n){    //插入排序 
	int temp;
	for(int i = 0;i=0){
			if(a[k]>temp){
				a[k+1] = a[k];
				--k;
			}
			else
				break;
		}
		a[k+1] = temp;
		}
}

void ShellSort(int a[], int n){   //希尔排序 
	int gap = n/2;
	int j,temp;
	while(gap!=0){
		for(int i=gap;i=0;j=j-gap){
				if(a[j]=point)
			high--;
		swap(a,low,high);
		while(low

你可能感兴趣的:(c++,c语言,算法)