Stack and Queue

This is a discussion on Stack and Queue within the C Programming forums, part of the General Programming Boards category; Which is better to determine stack and queue and why? XD - First In First Out - First In Last ...

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    Smile Stack and Queue

    Which is better to determine stack and queue and why? XD

    - First In First Out
    - First In Last Out
    - Last In First Out
    - Last In Last Out

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Um, are you taking some C quiz online?

    What do you mean by "better"? We're talking definitions here. A stack is one way and a queue is another.

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    A queue is a First In First Out (FIFO). Because the first element stored in the queue will first go out :P
    Like you have:
    1-2-3-4-5
    you insert another one:
    1-2-3-4-5-6
    If you take one you ll start first from the beginning (from 1, 2 etc)

    A stack is Last in First Out. Because if you inserted 6 (push) and you wanted to get an element from the stack (pull), you would get 6, then 5 etc etc

    That's not something you could find by googling though!!
    Last edited by C_ntua; 07-03-2008 at 02:50 PM.

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    242
    There is no better; the stack works on LIFO, and the queue works on FIFO.

  5. #5
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    I mean, why you choose to say stack is LIFO not FILO, and queue is FIFO not LILO? XD

  6. #6
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Well, just...because. It is the same thing anyhow.
    People usually see it at the scope of extracting data. If you want 10 elements from a stack you ask yourself "what will I get"? The answer is FIRST you ll get the values stored LAST.
    You don't care that the last element will be taken last. You care about the data that you will get now. So FIFO is more "nice" than LILO.

    EDIT: Don't ask why we say LIFO and not FOLI :P

  7. #7
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    So it's depend on what we care or not...

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Queues and Stacks are the concept which is there, and you know what they. Its very important to know how they work. Once you get the grip of that. You could answer any question regarding that. After that its upto to you call its as FILO or LIFO.

    Its like my name is Harish Shivaraj in here where I stay. But when I get back to home country my name is S.Harish. or Harish S. There just different. As a person i am still the same

    ssharish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 02:55 AM
  2. Pushing a Queue onto a Stack?
    By MiroMage in forum C Programming
    Replies: 5
    Last Post: 10-14-2008, 09:23 PM
  3. Queue Stack Palindrome
    By silicon in forum C++ Programming
    Replies: 20
    Last Post: 07-15-2004, 03:38 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. queue / stack
    By smd in forum C++ Programming
    Replies: 2
    Last Post: 07-26-2002, 01:30 PM

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