Re: implement stack and queue in C or in asm

Discussion in 'C Programming' started by Dr Malcolm McLean, Apr 4, 2010.

  1. On 3 Apr, 19:26, "io_x" <> wrote:
    >
    > than why stack and queue are seen from all one as
    > different data structures?
    > there is a push in the tail and a pop in the tail (stack)
    > but could be
    > a push in the head and a pop in the head too.
    >

    The obvious way to implement a stack is with a memory buffer which
    grows in one direction, either upwards or downwards in memory, and
    with a single "top" index or pointer. The obvious way to implement a
    queue is with a fixed-size memory buffer which grows from one end and
    shrinks from the other, eventually looping back on itself in a circle,
    and with "head" and "tail" indices or pointers.
    However the details aren't really important. You can implement
    both with linked lists, for example. The reason we use the structures
    is because of the algorithms. An algorithm that traverse a tree will
    naturally use a stack. An algorithm that schedules jobs to be passed
    to another process will naturally use a queue.
    Dr Malcolm McLean, Apr 4, 2010
    #1
    1. Advertising

  2. On 4 Apr, 09:09, "io_x" <> wrote:
    > "Dr Malcolm McLean"  ha scritto nel messaggio
    >
    > >     However the details aren't really important.

    >
    > the details are important!
    >

    What usually matters is the behaviour and the big O complexity of the
    functions. Exactly how they are written is of less importance. Micro-
    optimisation can produce very significant speedups, but these vary
    from platform to platform, and only make a real difference to the
    running time of the program if embedded in a routine which itself
    accounts for a large part of the running time of the program - almost
    always you find that there is one tight inner loop which dominates
    runtime.
    Dr Malcolm McLean, Apr 4, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Russell Warren

    Is Queue.Queue.queue.clear() thread-safe?

    Russell Warren, Jun 22, 2006, in forum: Python
    Replies:
    4
    Views:
    670
    Russell Warren
    Jun 27, 2006
  2. Kceiw
    Replies:
    3
    Views:
    982
    Jim Langston
    Mar 14, 2006
  3. asximos

    how to implement stack work as a queue

    asximos, Nov 24, 2008, in forum: C Programming
    Replies:
    0
    Views:
    403
    asximos
    Nov 24, 2008
  4. Pascal J. Bourguignon

    Re: implement stack and queue in C or in asm

    Pascal J. Bourguignon, Apr 3, 2010, in forum: C Programming
    Replies:
    0
    Views:
    1,552
    Pascal J. Bourguignon
    Apr 3, 2010
  5. Kris
    Replies:
    0
    Views:
    467
Loading...

Share This Page