Cancel
Showing results for 
Search instead for 
Did you mean: 

Read Stack and Queue

Valued Contributor
Valued Contributor

Hi,

 

How can i read all stack or a queue entys without removing them ? When i use pop they will be deleted.

6 REPLIES 6

Re: Read Stack and Queue

Creator
Creator

Hi Readock,

 

try "top" for stacks and queues

 

Re: Read Stack and Queue

Siemens Phenom Siemens Phenom
Siemens Phenom

I would advide to use a list/CardFile instead of a stack/StackFile. So you can use the method 'read' for nondestructive readout.

 

You can push and pop values onto/from a list/CardFile like this:

CardFile.append("hello"); -- StackFile.push("hello")
CardFile.append("world"); -- StackFile.push("world")

print CardFile[CardFile.dim]; -- print StackFile.pop
print CardFile[CardFile.dim]; -- print StackFile.pop

 

Alternatively you could copy the stack and read out the copy. But I would advise against it, because this would be very slow.

_________________________________________________________________
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: Read Stack and Queue

Valued Contributor
Valued Contributor

ok i want to edit a Stack in a Method and then use it as normal so i cant take a CardFile. And i want to edit not just the first entry. It don't need to be fast because it will be done only once at the beginning. Can you give a example code with the list ? (havn't worked much with it)

Re: Read Stack and Queue

Siemens Phenom Siemens Phenom
Siemens Phenom

I have no idea what you mean with edit a Stack in a Method.

Do you want to read out each element and alter it?

 

What you need to know about the data type 'list' is, that the brackets [] alter the list: reading via brackets removes the value, writing via brackets inserts the value.

 

Example for a list:

is
    li : list;
do
    li.create;
    li.append("1");
    li.append("2");
    li.append("3");

    -- read out all elements
    for local i := 1 to li.dim loop
        print li.read(i);
    next;

    print;

    -- append "x" to each element
    for local i := 1 to li.dim loop
        li[i] := li[i] + "x";
    next;

    -- pop the values in reverse order (LIFO) from the list
    for local i := li.dim downto 1 loop
        print li[i];
    next;

-- 'li' is empty now end;

 

_________________________________________________________________
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: Read Stack and Queue

Valued Contributor
Valued Contributor

I want for example to replace an entry or print an entry value. So something like this (pseudocode):

 

is
    l:list;
do
    l.create;
    l := StackFile.copy();
    print l[2];
    l[2] := "New Value";
    CardFile.setContend(l);
end;

StackEdit.PNG

 

 

 

 

 

Re: Read Stack and Queue

Siemens Phenom Siemens Phenom
Siemens Phenom
is
    li : list;
do
    li.create;
    li.appendList(StackFile.copy);

    li.cutRow(2);         -- remove element 2
    li[2] := "new value"; -- re-insert element 2

    StackFile.delete;
    StackFile.pushList(li);
end;

 

_________________________________________________________________
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.