Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

急~~~一個c語言讀file的問題

請問各位高手

有沒有辦法把兩個檔案(檔案裡各有排序好的數字)

想要將兩個檔案寫入第3個檔案

然後是排序好的(不使用到array!!)

Update:

那個...可以白話一點嗎?

因為我剛學ds

謝謝囉

2 Answers

Rating
  • 2 decades ago
    Favorite Answer

    學過merge SORT嗎?

    如果學過的話就用merge SORT就好了~

    觀念為:

    剛開始先從二個FILE裡都讀一個數字出來~

    然後來做比較~

    比較小的數字就存入第三個檔案裡~

    然後存比較小的數字的那變數就再從檔案裡讀一個~

    這樣一直比到FEOF為止~

    再把沒讀完的檔案全都存到第三個檔案裡~

    破破爛爛的ex圖示:

    file 1:

    56 100 300 536 889 1000........

    file 2:

    1 8 9 11 80 99 632 684...........

    file 3:

    NULL

    ----------------------------------------用個指標來讀檔--------------------------------

    file 1:

    56 100 300 536 889 1000........

    指標指向56

    file 2:

    1 8 9 11 80 99 632 684...........

    指標指向1

    file 3:

    NULL

    ----------------------------------------經過第一次處理--------------------------------

    file 1:

    56 100 300 536 889 1000........

    指標指向56

    file 2:

    1 8 9 11 80 99 632 684...........

    指標指向8

    file 3:

    1

    ----------------------------------------經過第二次處理--------------------------------

    file 1:

    56 100 300 536 889 1000........

    指標指向56

    file 2:

    1 8 9 11 80 99 632 684...........

    指標指向9

    file 3:

    1 8

    ----------------------------------------經過第三次處理--------------------------------

    file 1:

    56 100 300 536 889 1000........

    指標指向56

    file 2:

    1 8 9 11 80 99 632 684...........

    指標指向11

    file 3:

    1 8 9

    一直跑到完為止= =+

    Source(s): 這顆破破爛爛的大腦
  • 2 decades ago

    用ado把兩個檔案當table,然後用SQL語法的table join與ORDER BY select出來後,寫回第三個檔案即可。

    Source(s): 自身的專業知識
Still have questions? Get your answers by asking now.