Thread: Linked Lists please help!!!

  1. #61
    Registered User
    Join Date
    Nov 2012
    Posts
    49
    Can anyone tell me how i can make a function that takes an Array and sorts it with the heap sort?

  2. #62
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I think that you should start a new thread for that. Furthermore, you should make an attempt before asking.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #63
    Registered User
    Join Date
    Nov 2012
    Posts
    49
    I have made many attempts... Because i am not sending my attempt (code) that's not mean that i haven't done anything and i want from you to solve it for me, i just want you if you can to explain me how the heap sort is because it's little bit confusing and i thing there are lots of ways to make a heap sorting of an array!!!
    Last edited by ValL; 11-29-2012 at 10:06 AM.

  4. #64
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by ValL View Post
    I have made many attempts... Because i am not sending my attempt (code) that's not mean that i haven't done anything and i want from you to solve it for me, i just want you if you can to explain me how the heap sort is because it's little bit confusing and i thing there are lots of ways to make a heap sorting of an array!!!
    Heapsort - Wikipedia, the free encyclopedia
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #65
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by ValL View Post
    Ok my friend i did what you told me as first step for the exercise... And it seems to wok fine but let me sent you the part i did to check it maybe i have done something wrong!!
    That's not really what I've had in mind.

    With your version you can only write the array to the file the first time. For the second time (writing out the heap sorted array) you would still need a second function.

    I would write the function in a way that you can use it for both writing operations. The main program would then look like
    Code:
    create_array(array, n);
    
    first_file = fopen(...);
    write_array(first_file, array, n);
    
    sort_array(array, n);
    
    second_file = fopen(...);
    write_array(second_file, array, n);
    In general a function should do one particular thing.
    Your function is calculating random numbers, assigns them to the array (and assumes that the first element is already written to the file), writes them to the file and prints them to the screen. Thus you can't use it in another part of your program because it is too specific.

    Bye, Andreas

  6. #66
    Registered User
    Join Date
    Nov 2012
    Posts
    49
    Hi, can anyone tell my how i can create an empty priority queue with doubly link lists? I can not understand how i must do it.
    Last edited by ValL; 12-04-2012 at 08:09 AM.

  7. #67
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Please reread this:
    Quote Originally Posted by laserlight View Post
    I think that you should start a new thread for that. Furthermore, you should make an attempt before asking.
    Fact - Beethoven wrote his first symphony in C

  8. #68
    Registered User
    Join Date
    Nov 2012
    Posts
    49
    Nice help!!! Thank you

  9. #69
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    That's wonderful. Now can we finally let this thread die? Thanks.

  10. #70
    Registered User
    Join Date
    Nov 2012
    Posts
    49
    Can you just say anything (small help) about what i have asked and do not tell me every time i ask something, to give you evidence for my attempts i have done? Is that difficult to you? Or maybe you can't just get over it that here i am not to copy anything and just paste it in my exercise so i will be done? Is just a simple thing. Say a few words of what i have asked and don't delve into everything i said to find a problem. There is not any problem my friend!! Thank you.

    P.S : And yes you can finally let this thread die...

  11. #71
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by ValL View Post
    Can you just say anything (small help) about what i have asked and do not tell me every time i ask something, to give you evidence for my attempts i have done?
    No. Forcing you to come up with your own solutions makes you a good programmer.

    If you just want to look at code that does what you want, use Google. You may say, "I don't want to just Google the answer, I want to learn how to program". There is no difference in getting code from us and Google.

    "Give a man a fish and he feeds that night; teach a man to fish and he feeds for life"
    Fact - Beethoven wrote his first symphony in C

  12. #72
    Registered User
    Join Date
    Nov 2012
    Posts
    49
    You still do not understand me... I do not want code neither from you or Google. I just want a small help, like we say mmm, the priority queue does that (and don't explain it like an encyclopedia), and you should make a function which checks that...(only 2 lines of explaining, not much). Is not that difficult. Not code and not much words.

    Thank you again!!!

  13. #73
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    and don't explain it like an encyclopedia), and you should make a function which checks that...(only 2 lines of explaining, not much). Is not that difficult. Not code and not much words.
    you dont want much do you.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  14. #74
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by http://en.wikipedia.org/wiki/Priority_queue
    ... a priority queue ... is like a regular queue ... data structure, but where ... each element has a "priority" associated with it.

    In a priority queue, an element with high priority is served before an element with low priority.

    If two elements have the same priority, they are served according to their order in the queue.

    ... elements are pulled in first-in first-out-order (e.g. a line in a cafeteria)

    A priority queue must at least support the following operations:

    - add an element to the queue with an associated priority
    - remove the element from the queue that has the highest priority, and return it
    Is that enough for you to go on? Try to understand and implement as best you can. If/when you get stuck or have further questions, create a new thread and clearly describe the problems you're getting or questions you have.

    Hopefully, this thread will be closed to prevent further ignoring the moderators advice to start a new thread.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Double Linked Dynamic Lists Vs Unrolled Linked Lists
    By lantzvillian in forum C Programming
    Replies: 6
    Last Post: 02-14-2012, 01:07 PM
  2. Replies: 4
    Last Post: 05-01-2010, 10:19 PM
  3. Question about Linked lists of lists
    By hear_no_evil in forum C Programming
    Replies: 2
    Last Post: 11-08-2004, 02:49 AM
  4. question on linked lists(stack with linked lists)
    By dionys in forum C Programming
    Replies: 1
    Last Post: 06-02-2004, 11:08 AM
  5. Linked List of Linked lists Revisited.
    By Qui in forum C++ Programming
    Replies: 11
    Last Post: 04-11-2004, 09:45 PM