字元排序課程設計
㈠ c++程序代碼,數據排序的課程設計,有詳細注釋!謝謝
#include<iostream>
#include<cstdlib>
using namespace std;
void select(int n);
void insert(int a[],int n);
void input1(int a[],int n);
void input2(int a[],int n);
void choose(int a[],int n);
void exchange(int a[],int n);
void merge(int a[],int left,int mid,int right);
void output(int a[],int n);
int main()
{
cout<<" 數據排序"<<endl;
cout<<" =============="<<endl;
cout<<endl;
cout<<" 1. 插入排序"<<endl;
cout<<" 2. 選擇排序"<<endl;
cout<<" 3. 交換排序"<<endl;
cout<<" 4. 歸並排序"<<endl;
cout<<endl;
cout<<" 請選擇(1~4,0:退出)"<<endl;
int select,n,way;
int *a;
cin>>select;
switch(select)
{
case 1:cout<<"插入排序"<<endl;
cout<<"請確定輸入數據個數:";
cin>>n;
a=new int [n];
cout<<"請選擇輸入方式:"<<"1為手工輸入,2為隨機生成"<<endl;
cin>>way;
switch(way){
default : cout<<"輸入錯誤!"<<endl;
case 1:input1(a,n);
insert(a,n);
output(a,n);
delete []a;
break;
case 2:input2(a,n);
insert(a,n);
output(a,n);
delete []a;
break;
}
break;
case 2:cout<<"選擇排序"<<endl;
cout<<"請確定輸入數據個數:";
cin>>n;
a=new int [n];
cout<<"請選擇輸入方式:"<<"1為手工輸入,2為隨機生成"<<endl;
cin>>way;
switch(way)
{
default : cout<<"輸入錯誤!"<<endl;
case 1:input1(a,n);
choose(a,n);
output(a,n);
delete []a;
break;
case 2:input2(a,n);
choose(a,n);
output(a,n);
delete []a;
break;
}
break;
case 3:cout<<"交換排序"<<endl;
cout<<"請確定輸入數據個數:";
cin>>n;
a=new int [n];
cout<<"請選擇輸入方式:"<<"1為手工輸入,2為隨機生成"<<endl;
cin>>way;
switch(way)
{
default : cout<<"輸入錯誤!"<<endl;
case 1:input1(a,n);
exchange(a,n);
output(a,n);
delete []a;
break;
case 2:input2(a,n);
exchange(a,n);
output(a,n);
delete []a;
break;
}
break;
case 4:cout<<"歸並排序"<<endl;
cout<<"請確定輸入數據個數:";
cin>>n;
a=new int [n];
cout<<"請選擇輸入方式:"<<"1為手工輸入,2為隨機生成"<<endl;
cin>>way;
switch(way)
{
default :cout<<"輸入錯誤!"<<endl;
case 1:input1(a,n);
merge(a,0,n/2,n);
output(a,n);
delete []a;
break;
case 2:input2(a,n);
merge(a,0,n/2,n);
output(a,n);
delete []a;
break;
}
break;
case 0:
break;
}return 0;
}
void input1(int a[],int n){
for(int i=0;i<n;i++)
cin>>a[i];
}
void input2(int a[],int n){
for(int i=0;i<n;i++)
a[i]=rand()%100;
for(int j=0;j<n;j++)
cout<<a[j]<<" ";
cout<<endl;
}
void output(int a[],int n){
for(int i=0;i<n;i++){
int k=0;
k++;
cout<<a[i]<<" ";
if(k%10==0)
cout<<endl;
}
}
void insert(int a[],int n){
int k;
for(int i=0;i<n-1;i++)
{
k=a[i+1];
int j=i;
while(j>=0&&k<a[j]) //若相鄰2數據順序不對
{
a[j+1]=a[j];;
j--;
}
a[j+1]=k; //到這里實現將每個i取值時順序不對的數據調換位置
}
}
void choose(int a[],int n){
int t,k;
for(int i=0;i<n-1;i++){
int j=i;
for(k=i+1;k<n;k++)
if(a[k]<a[j]) //順序不對,將較小的數據下標傳遞給j
j=k;
if(j!=i)
{
int t=a[i]; //將這2數據順序交換,實現正序排列
a[i]=a[j];
a[j]=t;
}
}
}
void exchange(int a[],int n){
int i,j;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j]){
int t=a[i];
a[i]=a[j];
a[j]=t;
}
}void merge(int a[],int left,int mid,int right)
{
int *b=new int [right-left+1];
int i=left,j=mid+1,k=0;
while((i<=mid)&&(j<=right))
if(a[i]<=a[j]) b[k++]=a[i++];
else b[k++]=a[j++];
while (i<=mid) b[k++]=a[i++];
while(j<=right) b[k++]=a[j++];
for(i=0,k=left;k<=right;) a[k++]=b[i++];
}
㈡ 課程設計,排序的綜合實現(直接插入,簡單選擇,快排,堆排,歸並)
(一)確定論文提要,再加進材料,形成全文的概要
論文提要是內容提綱的雛型。一般書、教學參考書都有反映全書內容的提要,以便讀者一翻提要就知道書的大概內容。我們寫論文也需要先寫出論文提要。在執筆前把論文的題目和大標題、小標題列出來,再把選用的材料插進去,就形成了論文內容的提要。
(二)原稿紙頁數的分配
寫好畢業論文的提要之後,要根據論文的內容考慮篇幅的長短,文章的各個部分,大體上要寫多少字。如計劃寫20頁原稿紙(每頁300字)的論文,考慮序論用1頁,本論用17頁,結論用1—2頁。本論部分再進行分配,如本論共有四項,可以第一項3—4頁,第二項用4—5頁,第三項3—4頁,第四項6—7頁。有這樣的分配,便於資料的配備和安排,寫作能更有計劃。畢業論文的長短一般規定為5000—6000字,因為過短,問題很難講透,而作為畢業論文也不宜過長,這是一般大專、本科學生的理論基礎、實踐經驗所決定的。
(三)編寫提綱
論文提綱可分為簡單提綱和詳細提綱兩種。簡單提綱是高度概括的,只提示論文的要點,如何展開則不涉及。這種提綱雖然簡單,但由於它是經過深思熟慮構成的,寫作時能順利進行。沒有這種准備,邊想邊寫很難順利地寫下去。
編寫要點
編寫畢業論文提綱有兩種方法:
一、標題式寫法。即用簡要的文字寫成標題,把這部分的內容概括出來。這種寫法簡明扼要,一目瞭然,但只有作者自己明白。畢業論文提綱一般不能採用這種方法編寫。
二、句子式寫法。即以一個能表達完整意思的句子形式把該部分內容概括出來。這種寫法具體而明確,別人看了也能明了,但費時費力。畢業論文的提綱編寫要交與指導教師閱讀,所以,要求採用這種編寫方法。
詳細提綱舉例
詳細提綱,是把論文的主要論點和展開部分較為詳細地列出來。如果在寫作之前准備了詳細提綱,那麼,執筆時就能更順利。下面仍以《關於培育和完善建築勞動力市場的思考》為例,介紹詳細提綱的寫法:
上面所說的簡單提綱和詳細提綱都是論文的骨架和要點,選擇哪一種,要根據作者的需要。如果考慮周到,調查詳細,用簡單提綱問題不是很大;但如果考慮粗疏,調查不周,則必須用詳細提綱,否則,很難寫出合格的畢業論文。總之,在動手撰寫畢業論文之前擬好提綱,寫起來就會方便得多。
㈢ 求數據結構課程設計報告,多關鍵字排序,急急急~~~
呵呵,我也很想知道k!
㈣ c語言 數據結構 排序綜合 課程設計
給你發了 不只3種 給你5種了 363173922的 記得給我加分 有問題加我再給你解決 沒分就免談 好了都給你搞定了
㈤ 選擇排序程序設計(輸入10個有符號十進制整數,排序後輸出) 求程序或課程設計
java的簡單排序,不知道你說的是哪一種語言,不過各種語言都是相通的大同版小異
package task1.Array;
import java.util.Arrays;
class ArraySort {
public void arraySort(int[] b) {
權for (int a : b) {
Arrays.sort(b);
System.out.print(a + " ");
}
}
public static void main(String[] args) {
ArraySort as = new ArraySort();
int[] b = { 1, 2, 45, 5, 68, 9, 78, 4, 52, 34, 5 };
as.arraySort(b);
}
}
㈥ 求一份多關鍵字排序程序課程設計
FEIYGJB;L M,D/.SDFJBLLN
㈦ 排序演算法課程設計
// 各種排序演算法匯總.cpp : 定義控制台應用程序的入口點。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
#include <stack>
#include <time.h>
#include <stdlib.h>
template < typename T >
class SqList
{
private:
int length;
T * r;
public://介面
SqList(int n = 0);//構造長度為n的數組
~SqList()
{
length = 0;
delete r;
r = NULL;
}
void InsertSort();//順序插入排序
void DisPlay();//輸出元素
void BInsertSort();//折半插入排序
void ShellSort(int dlta[],int t);//希爾排序
void QuickSort();//快速排序
void SelectSort();//簡單選擇排序
void BubbleSort();//改進冒泡排序
void Bubble_Sort2();//相鄰兩趟是反方向起泡的冒泡排序演算法
void Bubble_Sort3();//對相鄰兩趟反方向演算法進行化簡,循環體中只包含一次冒泡
void HeapSort();//堆排序
void Build_Heap_Sort();//堆排序由小到大序號建立大根堆
void MergeSort();//歸並排序
void OE_Sort();//奇偶交換排序的演算法
void Q_Sort_NotRecurre();//非遞歸快速排序
void HeapSort_3();//三叉堆排序
public://調用
void ShellInsert(int dk);//一趟希爾排序
void QSort(int low,int high);//快速排序
int Partition(int low,int high);//一趟快速排序
int SelectMinKey(int i);//從i到length中選擇最小值下標
void HeapAdjust(int s,int m);//調整s的位置,其中s+1~m有序
void HeapAdjust_3(int s,int m);//三叉堆****調整s的位置,其中s+1~m有序
void Merge(T SR[],T TR[],int i,int m,int n);//歸並
void MSort(T SR[],T TR1[],int s,int t);//歸並
void Easy_Sort(int low,int high);//3個數直接排序
void Build_Heap(int len);//從低下標到高下標逐個插入建堆的演算法***建立大根堆**但為排序
};
template < typename T >
SqList<T>::SqList(int n = 0)
{
//srand( time(0) );
length = n;
r=new T[length+1];
T t;
cout<<"隨機生成"<<n<<"個值:"<<endl;
for (int i=1;i<=length;i++)
{
//cin>>t;
r[i] = rand()%1000;
//r[i] = t;
}
for (int i=1; i<=length;i++)
cout<<r[i]<<",";
cout<<endl;
}
template < typename T >
void SqList<T>::InsertSort()
{
int i,j;
for (i=2;i<=length;i++)
{
if (r[i]<r[i-1])
{
r[0]=r[i];
r[i]=r[i-1];
for (j=i-2;r[0]<r[i-2];j--)
r[j+1]=r[j];
r[j+1]=r[0];
}
}
}
template < typename T >
void SqList<T>::DisPlay()
{
int i;
cout<<length<<" 元素為:"<<endl;
for (i = 1;i < length+1;i++ )
{
cout<<r[i]<<" ,";
}
cout<<endl;
}
template < typename T >
void SqList<T>::BInsertSort()
{
int i, j, m;
int low,high;
for (i = 2;i<= length;i++)
{
r[0]=r[i];
low=1;
high=i-1;
while (low<=high)
{
m = (low+high)/2;
if ( r[0] < r[m] )
high=m-1;
else
low=m+1;
}
for ( j=i-1;j >=high+1; j--)
{
r[j+1] = r[j];
}
r[high+1] = r[0];
}
}
template < typename T >
void SqList<T>::ShellInsert(int dk)
{
int i,j;
for (i=dk+1;i<=length;i++)
if (r[i] < r[i-dk])
{
r[0] = r[i];
for ( j=i-dk; j>0 && r[0] < r[j]; j-=dk)
{
r[j+dk]=r[j];
}
r[j+dk] = r[0];
}
}
template < typename T >
void SqList<T>::ShellSort(int dlta[],int t)
{
int k=0;
for (;k<t;k++)
{
ShellInsert(dlta[k]);
}
}
template < typename T >
int SqList<T>::Partition(int low,int high)
{
int pivotkey;
r[0] = r[low];//記錄樞軸值
pivotkey = r[low];
while (low < high)
{
while (low < high&& r[high] >= pivotkey)
high--;
r[low] = r[high];
while (low < high&& r[low] <= pivotkey)
low++;
r[high] = r[low];
}
r[low] = r[0];//樞軸記錄到位
return low;//返回樞軸位置
}
template < typename T >
void SqList<T>::QSort(int low,int high)
{
int pivotloc;
if (low < high)
{
pivotloc = Partition(low,high);
QSort(low,pivotloc-1);
QSort(pivotloc+1,high);
}
}
template < typename T >
void SqList<T>::QuickSort()
{
QSort(1,length);
}
template < typename T >
int SqList<T>::SelectMinKey(int i)
{
int j,min=i;
for (j=i;j <= length;j++)
{
if (r[min] > r[j])
{
min = j;
}
}
return min;
}
template < typename T >
void SqList<T>::SelectSort()
{
int i,j;
T t;
for (i=1;i < length;i++)//循環length-1次不是length次
{
j=SelectMinKey(i);
if (i != j)
{
t= r[j];
r[j]=r[i];
r[i]=t;
}
}
}
template < typename T >
void SqList<T>::BubbleSort()
{
int i,j;
int flag=1;//標識位,如果出現0,則沒有交換,立即停止
T t;
for (i=1;i < length && flag;i++)
{
flag = 0;
for (j=length-1;j>=i;j--)
if (r[j]>r[j+1])
{
t=r[j];
r[j]=r[j+1];
r[j+1]=t;
flag=1;
}
}
}
template < typename T >
void SqList<T>::Bubble_Sort2()
{
bool change = true;
int low = 1, high = length;
int i;
T t;
while ( (low < high) && change )
{
change = false;
for ( i = low; i < high; i++ )
{
if ( r[i] > r[i+1] )
{
t = r[i];
r[i] = r[i+1];
r[i+1] = t;
change = true;
}
}
high-=1;
for ( i = high; i > low; i-- )
{
if ( r[i] < r[i-1] )
{
t = r[i];
r[i] = r[i-1];
r[i-1] = t;
change = true;
}
}
low+=1;
}
}
template < typename T >
void SqList<T>::Bubble_Sort3()
{
int i,d=1;
bool change = true;
int b[3] = {1,0,length};//b[0]為冒泡的下界,b[ 2 ]為上界,b[1]無用
T t;
while (change)//如果一趟無交換,則停止
{
change = false;
for ( i=b[1-d]; i!=b[1+d]; i=i+d )//統一的冒泡演算法
{
if ( (r[i]-r[i+d])*d > 0 )///注意這個交換條件
{
t = r[i];
r[i] = r[i+d];
r[i+d] = t;
change = true;
}
}
d = d*(-1);//換個方向
}
}
template < typename T >
void SqList<T>::HeapAdjust(int s,int m)
{
/* 已知H.r[s..m]中記錄的關鍵字除H.r[s].key之外均滿足堆的定義,本函數 */
/* 調整H.r[s]的關鍵字,使H.r[s..m]成為一個大頂堆(對其中記錄的關鍵字而言) */
int j;
T rc = r[s];
for (j=2*s;j <= m;j*=2)
{
/* 沿key較大的孩子結點向下篩選 */
if (j < m && r[j] < r[j+1])
j++;/* j為key較大的記錄的下標 */
if (rc >= r[j])
break;/* rc應插入在位置s上 ,無需移動*/
r[s]=r[j];
s=j;
}
r[s]=rc;/* 插入 */
}
template < typename T >
void SqList<T>::HeapSort()
{
/* 對順序表H進行堆排序。演算法10.11 */
T t;
int i;
for (i=length/2;i>0;i--)/* 把H.r[1..H.length]建成大頂堆 */
HeapAdjust(i,length);
for (i=length;i>1;i--)
{
/* 將堆頂記錄和當前未經排序子序列H.r[1..i]中最後一個記錄相互交換 */
t=r[1];
r[1]=r[i];
r[i]=t;
HeapAdjust(1,i-1);/* 將H.r[1..i-1]重新調整為大頂堆 */
}
}
template < typename T >
void SqList<T>::Build_Heap_Sort()
{
int i;
Build_Heap(length);
for ( i = length; i > 1; i-- )
{
T t;
t = r[i];
r[i] = r[1];
r[1] = t;
Build_Heap(i-1);
}
}
template < typename T >
void SqList<T>::Build_Heap(int len)
{
T t;
for (int i=2; i <= len; i++ )
{
int j = i;
while ( j != 1 )
{
int k = j/2;
if ( r[j] > r[k] )
{
t = r[j];
r[j] = r[k];
r[k] = t;
}
j = k;
}
}
}
template < typename T >
void SqList<T>::Merge(T SR[],T TR[],int i,int m,int n)
{
/* 將有序的SR[i..m]和SR[m+1..n]歸並為有序的TR[i..n] 演算法10.12 */
int j,k,x;
for (j=m+1,k=i;j<=n&&i<=m;k++)/* 將SR中記錄由小到大地並入TR */
{
if (SR[i]<SR[j])
TR[k]=SR[i++];
else
TR[k]=SR[j++];
}
if (i<=m)
for (x=0;x<=m-i;x++)
TR[k+x]=SR[i+x];/* 將剩餘的SR[i..m]復制到TR */
if (j<=n)
for (x=0;x<=n-j;x++)
TR[k+x]=SR[j+x];/* 將剩餘的SR[j..n]復制到TR */
}
template < typename T >
void SqList<T>::MSort(T SR[],T TR1[],int s,int t)
{
/* 將SR[s..t]歸並排序為TR1[s..t]。演算法10.13 */
int m;
T *TR2=new T[length+1];
if (s==t)
TR1[s]=SR[s];
else
{
m=(s+t)/2;/* 將SR[s..t]平分為SR[s..m]和SR[m+1..t] */
MSort(SR,TR2,s,m);/* 遞歸地將SR[s..m]歸並為有序的TR2[s..m] */
MSort(SR,TR2,m+1,t);/* 遞歸地將SR[m+1..t]歸並為有序的TR2[m+1..t] */
Merge(TR2,TR1,s,m,t);/* 將TR2[s..m]和TR2[m+1..t]歸並到TR1[s..t] */
}
}
template < typename T >
void SqList<T>::MergeSort()
{
MSort(r,r,1,length);
}
template < typename T >
void SqList<T>::OE_Sort()
{
int i;
T t;
bool change = true;
while ( change )
{
change = false;
for ( i=1;i<length;i+=2 )
{
if (r[i] > r[i+1])
{
t = r[i];
r[i] = r[i+1];
r[i+1] = t;
change = true;
}
}
for ( i=2;i<length;i+=2 )
{
if ( r[i] > r[i+1] )
{
t = r[i];
r[i] = r[i+1];
r[i+1] = t;
change = true;
}
}
}
}
typedef struct
{
int low;
int high;
}boundary;
template <typename T >
void SqList<T>::Q_Sort_NotRecurre()
{
int low=1,high=length;
int piv;
boundary bo1,bo2;
stack<boundary> st;
while (low < high)
{
piv = Partition(low,high);
if ( (piv-low < high-piv) && (high-piv > 2) )
{
bo1.low = piv+1;
bo1.high = high;
st.push(bo1);
high = piv-1;
}
else if ( (piv-low > high-piv) && (piv-low >2) )
{
bo1.low = low;
bo1.high = piv-1;
st.push(bo1);
low = piv+1;
}
else
{
Easy_Sort(low,high);
high = low;
}
}
while ( !st.empty() )
{
bo2 = st.top();
st.pop();
low = bo2.low;
high = bo2.high;
piv = Partition(low, high);
if ( (piv-low < high-piv) && (high-piv > 2) )
{
bo1.low = piv+1;
bo1.high = high;
st.push(bo1);
high = piv-1;
}
else if ( (piv-low > high-piv) && (piv-low >2) )
{
bo1.low = low;
bo1.high = piv-1;
st.push(bo1);
low = piv+1;
}
else
{
Easy_Sort(low,high);
}
}
}
template < typename T >
void SqList<T>::Easy_Sort(int low,int high)
{
T t;
if ( (high-low) == 1 )
{
if ( r[low] > r[high] )
{
t = r[low];
r[low] = r[high];
r[high] = t;
}
}
else
{
if ( r[low] > r[low+1] )
{
t = r[low];
r[low] = r[low+1];
r[low+1] = t;
}
if ( r[low+1] > r[high] )
{
t = r[low+1];
r[low+1] = r[high];
r[high] = t;
}
if ( r[low] > r[low+1] )
{
t = r[low];
r[low] = r[low+1];
r[low+1] = t;
}
}
}
template < typename T >
void SqList<T>::HeapAdjust_3(int s,int m)
{
T rc = r[s];
for (int j = 3*s-1; j <= m;j=j*3-1)
{
if (j+1<m)//有3個孩子結點
{
if ( rc>=r[j] && rc>=r[j+1] && rc>=r[j+2] )
break;
else
{
if ( r[j] > r[j+1] )
{
if ( r[j] > r[j+2] )
{
r[s]=r[j];
s=j;
}
else//r[j]<=r[j+2]
{
r[s]=r[j+2];
s=j+2;
}
}
else//r[j]<=r[j+1]
{
if ( r[j+1] > r[j+2] )
{
r[s]=r[j+1];
s=j+1;
}
else//r[j+1]<=r[j+2]
{
r[s]=r[j+2];
s=j+2;
}
}
}
}
if ( j+1==m )//有2個孩子結點
{
if ( rc>=r[j] && rc>=r[j+1] )
break;
else
{
if ( r[j] > r[j+1] )
{
r[s]=r[j];
s=j;
}
else//r[j]<=r[j+1]
{
r[s]=r[j+1];
s=j+1;
}
}
}
if (j==m)//有1個孩子結點
{
if ( rc>=r[j] )
break;
else
{
r[s]=r[j];
s=j;
}
}
}
r[s]=rc;
}
template <typename T >
void SqList<T>::HeapSort_3()
{
int i;
T t;
for (i=length/3; i>0; i--)
HeapAdjust_3(i,length);
for ( i=length; i > 1; i-- )
{
t = r[i];
r[i] = r[1];
r[1] = t;
HeapAdjust_3(1,i-1);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
SqList<int> Sq(15);
//Sq.InsertSort();
//Sq.BInsertSort();
/* 希爾排序*/
// int a[5]={5,4,3,2,1};
// Sq.ShellSort(a,5);
/* Sq.QuickSort();*/
// Sq.SelectSort();
/* Sq.BubbleSort();*/
/* Sq.HeapSort();*/
/* Sq.MergeSort();*/
/* Sq.Q_Sort_NotRecurre();*/
/* Sq.Bubble_Sort2();*/
/* Sq.OE_Sort();*/
/* Sq.Bubble_Sort3();*/
/* Sq.Build_Heap_Sort();*/
Sq.HeapSort_3();
Sq.DisPlay();
system("pause");
return 1;
}
㈧ c語言題目:用指向指針的方法對n個字元串排序並輸出
#include<stdio.h>
#include<string.h>
int main()
{ int n,i,j;
char s[100][20],*p[100],*t;
scanf("%d",&n);
for(i=0;i<n;i++)
{scanf("%s",s[i]);
p[i]=s[i];
}
for(i=0;i<n-1;i++)
for(j=0;j<n-1-i;j++)
if(strcmp(p[j],p[j+1])>0)
{t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}
puts("============");
for(i=0;i<n;i++)
puts(p[i]);
return 0;
}