-
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!
-
What's a partition, with respect to this list data type?
-
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.
-
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>
-
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.
-
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.
-
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.
-
If I am understanding your original post correctly, that is the right answer.
-
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...
-
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.
-
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?
-
Ok... well that illustrates the whole partition thing more clearly. Yeah it looks good to me.
-
Thanks for the help everyone!
-
No sweat. In the real world, you typically define the "fence" whenever you call a function. But I am not your teacher so whatever.
-
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>.