摘要:
#ifndef QUICK_SORT_H#define QUICK_SORT_H#include<assert.h>template<class T,int n>void swap(T* s,int i,int j){ assert((i<n)&&(j<n)); T temp=s[i]; s[i]=s[j]; s[j]=temp;}template<class T,int n>int partition(T* s,int start,int end){ int i= start; int devide_line=start; in 阅读全文
摘要:
#ifndef HEAP_SORT_H#define HEAP_SORT_H#include<assert.h>template<class T,int n>inline void swap(T* s,int i,int j){ assert((i<n)&&(j<n)); T temp=s[i]; s[i]=s[j]; s[j]=temp;}template<class T,int n>inline int leftChild(int i){ return 2*i+1;}template<class T,int n>i 阅读全文
摘要:
#ifndef MERGE_SORT_H#define MERGE_SORT_H#include<string>static int count =0;template<class T,int n>void merge(T* s,int i,int j,int m)//s : i.....,m,m+1,.....j{ T* ls = new T[m-i+2]; memcpy(ls,s+i,(m-i+1)*sizeof(T)); ls[m-i+1]=INT_MAX; T* rs = new T[j-m+1]; memcpy(rs,s+m+1,(j-m)*sizeof(T) 阅读全文
摘要:
#ifndef BUBBLE_SORT_H#define BUBBLE_SORT_H#include<assert.h>template<class T,int n>inline void swap(T* s,int i,int j){ assert((i<n)&&(j<n)); T temp=s[i]; s[i]=s[j]; s[j]=temp;}template<class T,int n>void bubble_up(T* s, int i){ for(int j=n-1;j-1>=i;j--) { if(s[j]&l 阅读全文