線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1201
推到 Plurk!
推到 Facebook!

關於merge sort 問題

尚未結案
qpe
一般會員


發表:1
回覆:0
積分:0
註冊:2004-10-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-10-25 11:51:06 IP:163.28.xxx.xxx 未訂閱
這個題目是你先輸入一個數n 然後在輸入兩個"實數" 然後用亂數產生器產生n個數介於這兩個實數之間 ex:假設你輸入n為5 兩個實數為20和1    那應該就要隨機產生五個介於20和1之間的數       ex: 7.1551  2.5476  1.5566 5.2222 1.2345                                                                        然後再用merge sort 的演算法由小到大排序 所以應該要出現為      1.2345 1.5566 2.5476 5.2222 7.1551                                                                       然後再把他cout出來           可是我的程式雖然可以compile 可是無法正確排序... 請高手幫幫我吧 以下是程式碼 ---------------------------------------------------------------------
    #include
#include
#include
#include
#include
using namespace std;
void merge(double [],int,int,int);
void merge_sort(double [],int, int);
inline double Rand() {return double (rand())/RAND_MAX;}    int main()
{
 int n;
 int temp;
 int a_min, a_max;
 cout<<"Please type a natual number n."<>n;
 cout<<"Please type upper bound & lower bound "<>a_max;
 double a[n];
         
 srand(time(0));
 cout<<"The following is the original array"<
---------------------------------------------------------------------    我是在unix環境下用g  編譯器編譯的
以下是執行結果
                                                                                
Please type a natual number n.
5
Please type upper bound & lower bound
10
1
The following is the original array
8.69872 8.133 2.76211 4.5573 6.01218
The following is the sorted array
-6.58201e 304-2.17526e 307-2.17518e 307-2.17547e 3070
                                                                                
顯然的排序的結果有問題,麻煩幫我看看吧 > <    --
新手上路 請多包含        發表人 - qpe 於 2004/10/25  11:58:37    發表人 - qpe 於 2004/10/25  11:59:56
        
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-10-26 20:20:03 IP:211.76.xxx.xxx 未訂閱
請參考: ■【發表】Merge Sort  http://delphi.ktop.com.tw/topic.php?TOPIC_ID=20799 ■【發表】Heap Sort  http://delphi.ktop.com.tw/topic.php?TOPIC_ID=20800    吃軟也吃硬 dllee.ktop.com.tw StatPlus 系統資源監測器 @ SoftKing VMASK - ViewMove Automation Software Kernel
------
http://www.ViewMove.com
系統時間:2024-06-29 15:21:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!