• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ help

Tommy2000GT

Golden Member
I am learning linked lists and stacks in my data structures class right now. I am having a difficult time understanding the concept of links lists and stacks because the instructor is hard to understand and the text book is horrible at explaining it. Does anyone know any websites with good tutorials on linked lists and stacks? I've tried searching some websites and their tutorials don't seem helpful.
 
A stack is basically an array that uses first in last out method of moving data. the last element you put in the array is the first to take out, known as pop. putting an element into the array is pushing. you can do all this with a regular array, the linked list part is just to make your program more efficient.

that link posted above my confuse you, it deals with linked lists in c, so if you haven't seen c code you may not know whats going on.
 
The original question was inquiring about STACKS in relation to LINKED LISTS. While it's true that arrays can be used as STACKS, there's no benefit to using arrays in this fashion (as they have direct random access to the various elements). Linked lists OTOH, unlike arrays, are boundless in size (as they can keep growing by adding new NODES to them). STACKS are indeed LIFO (last in first out). QUEUES are FIFO (first in first out). Here's an easy way to remember the two:

For STACKS, think of a STACK OF PLATES. You ADD plates to the TOP OF THE STACK. When you're ready to GRAB a plate, you REMOVE it off the TOP OF THE STACK as well. Which is the plate that was removed? The LAST ONE ADDED to the stack. (LAST IN, FIRST OUT)

For QUEUES, think of a CALLER QUEUE. You call in for customer service at company XYZ. All representatives are BUSY, but your call will be answered in the order in which it was received. Thus, the FIRST PERSON added to the QUEUE is the FIRST PERSON to receive assistance when a representative becomes available. (FIRST IN, FIRST OUT)

Linked lists are data structures which can be used to create STACKS, QUEUES, TREES, etc. The underlying methods of your linked list class(es) (PUSH, POP, etc.) and their ATTRIBUTES (NEXT NODE, PREV NODE, LEFT NODE, RIGHT NODE, etc.) control the implementation of the linked list.

For STACKS and QUEUES, you can have the same LINKED LIST classes with slightly different PUSH and/or POP methods as follows:

[*]STACKS:
The PUSH method adds a new node to the TOP of the linked list
The POP method removes and returns the node at the TOP of the linked list (resulting in LAST IN, FIRST OUT)

[*]QUEUES:
The PUSH method adds a new node to the BOTTOM of the linked list
The POP method removes and returns the node at the TOP of the linked list (resulting in FIRST IN, FIRST OUT)
 
Back
Top