Thread: File data sorting

  1. #1
    Registered User
    Join Date
    Apr 2002

    File data sorting

    Any tips on how to sort a file with random numbers using the fwrite, fseek, and fscan without using an array? I want to be able to make a copy of the file, sort it in increasing order, and print out the sorted data.


  2. #2
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002

    Thumbs up

    One possibility that i can see to sort the recs in a file with out using arrays is that u create a temporary file (initially blank).
    U first scan the entire source file for the smallest valued record (and fix an index there). Once the file is scanned, pick the indexed record and dump it in the other file. Repeat the process for the next record and so on.

    Yeah...this is a very search-intensive process, but thats all i can think of right now...

    Happy coding...

    Help everyone you can

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Read the file into a binary tree and then print it out to the new file with an in-order traversal. The file is sorted because binary trees by nature sort the data inserted into them.

    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. spell check in C using a dictionary file
    By goron350 in forum C Programming
    Replies: 10
    Last Post: 11-25-2004, 06:44 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM