Thread: separating mixed list into sorted two lists

  1. #16
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    "sort odd file
    sort even file"

    i cant read files more then once??

    " append to odd ? odd file : even"

    what this means?
    i know the ? : form
    what you mean here?

  2. #17
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Ohh man, you really need help. He gave a whole lot of hints

    I am waiting for Quzah's comments

    -ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You don't have to read a file to append to it. Therefore, since you can only read each file once:

    1 - Open the mixed file for reading.
    2 - Open output.odd in append mode.
    3 - Open output.even in append mode.
    4 - Read the input file, appending as you go to the appropriate file.
    5 - Close the input all the files.
    6 - Open one of the output files for reading/writing.
    7 - Read it into memory and sort it.
    8 - Write it.
    10 - Do steps 6 through 8 for the other output file.

    There. Each file has been read only one time.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i am not allowed to use append
    only "r" for the input
    and "w" for the two output files

  5. #20
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I doubt that. You aren't telling us the full requirements. How about in the future you actually tell us what the requirements of your homework are, since we're doing all the work here anyway. That way it will save us all a bunch of time.

    You cannot perform this task in the manner you describe. Without being able to sort the data in memory, and with only being able to open in write mode, and with only being able to read through the input file once, and limiting yourself to two output files, you cannot do this task as you've described.

    You're either not understanding the question, or are making stuff up because you don't like the answers you were given. If you cannot sort the file on disk, then you MUST sort it in memory. That's all there is to it. You either read through the file a bunch of times, or you read it once and sort it in memory. Pick one.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #21
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    ok ill try to implement your solution.

    nut i cant understand what append mode does.
    i read in the manual of c++ that its "writing from the end"
    so its moving the EOF forward and replacing the empty new space with the new data??

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by transgalactic2 View Post
    ok ill try to implement your solution.

    nut i cant understand what append mode does.
    i read in the manual of c++ that its "writing from the end"
    so its moving the EOF forward and replacing the empty new space with the new data??
    Append mode works just like write mode, with the difference that it does a fseek(file, 0, SEEK_END) - that is, it positiions the "where to access the file next" at the end of the file, so when you write to it, it adds to the end of the file, rather than writing at the first location of the file.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #23
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    can you see a solution which uses

    my helping function??

    i am supposed to use it in the solution somehow
    ?

  9. #24
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    is there a way?

  10. #25
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I've already told you, you are either going to have to read your file(s) more than once, or you're going to have to sort the entire thing in memory.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Merging two lists as one
    By Lone in forum C++ Programming
    Replies: 1
    Last Post: 03-17-2005, 03:59 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM