Appending a list!

This is a discussion on Appending a list! within the C++ Programming forums, part of the General Programming Boards category; Quick list question. If I have an empty list where would I append the first value of the list. The ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    133

    Appending a list!

    Quick list question.

    If I have an empty list where would I append the first value of the list.

    The definition of append in the question says "append an element at the end of the right partition".

    This is why I am confused... With an empty list <> the 'fence' of the list I'm assuming is <|>.

    So if I have these commands...

    L1.append(10);
    L1.append(20);
    L1.append(15);

    whould the list look like this? <10,20,15> or <10,20,15>

    I think the main issue I am having is after L1.append(10) I don't know where the fence would be located...

    <10|> or <|10>

    any help would be great!
    Last edited by GCNDoug; 10-06-2008 at 01:50 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,786
    What's a partition, with respect to this list data type?
    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. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Since "fence" is not a term normally associated with a list, who knows? But the empty list is probably <|>, yes, and then putting 10 at the end of the right partition I would think would do <|10>. But you would have to look at book/notes to be sure of the notation.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    133
    This is for a data organization class. The fence is '|' I had never heard of a fence until this programming class I thought maybe it was the current pointer I'm not sure. The right partition would be to the right of the fence. So if I had

    <20, 23 | 12, 15> - List of four elements (12 and 15 are in the right partition of the list)

    L1.insert(10);

    <20, 23 | 10, 12, 15>

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I assume the whole fence thing is just your teacher's pet name for a pipe. Or perhaps the pipe is being called a fence to visually denote a logical concept. Not to insult you or anything but could I just rephrase your question to:

    if I have a | and put 10 after it, then append 20 into the list, and then append 15 to the list, where in my list is |?

    That is my current understanding of the question. And apparently it is also tabstops understanding too.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,786
    Okay, so given <w, x | y, z>, which variables are at the start and end of the left and right partitions? Once you know this, you can interpret the question correctly.
    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

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    133
    Left partition

    Start W
    Edn X

    Right partiton

    Start Y
    End Z

    I think lol....

    I am thinking that <| 10, 20, 15> is the right order of the list with the fence remaining at the beginnning.

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    If I am understanding your original post correctly, that is the right answer.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,786
    When in doubt, confirm with your teacher. Obviously, if your interpretation is correct, then <| 10, 20, 15> is indeed the correct result, but if your interpretation is wrong...
    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

  10. #10
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I am not liking the whole fence analogy. It doesn't make the concept clear at all. I don't think the visuals correspond well to what is going on in the question. But I do believe that your logic is sound.

  11. #11
    Registered User
    Join Date
    Apr 2007
    Posts
    133
    I worked the second part out and hopefully you guys can check me.

    L1.append(10);
    L1.append(20);
    L1.append(15);

    <| 10, 20, 15>

    L1.setStart(); - "Place fence at list start, making left partition empty"

    ...The fence never moved this is either pointless or I did something wrong...

    <| 10, 20, 15>

    L1.insert(39);

    <| 39, 10, 20, 15>

    L1.next();

    < 39 | 10, 20, 15>

    L1.insert(12);

    < 39 | 12, 10, 20, 15> - Finished answer...

    Look ok?

  12. #12
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok... well that illustrates the whole partition thing more clearly. Yeah it looks good to me.

  13. #13
    Registered User
    Join Date
    Apr 2007
    Posts
    133
    Thanks for the help everyone!

  14. #14
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    No sweat. In the real world, you typically define the "fence" whenever you call a function. But I am not your teacher so whatever.

  15. #15
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    I believe it is correct.
    As for your append concern I am pretty sure you do it correct. If you have <a, b | c, d> and you append at the start of right partition you would do <a,b | x, c, d>. At the end of the right partition you would do <a,b | c,d,x>. In either way the "right partition" means that wherever you append the fence will always be left. So in an empty list of course the fence will be like <|10>.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 08:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 04:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21