Changes

Jump to: navigation, search

C/C++ FAQ

1,428 bytes added, 20:32, 8 November 2012
C/C++ FAQ
<br>'''Submitted by:''' Team 6 <br><br>
----
<br><br>
'''Q:''' Can Stacks, Queues or Lists be referenced using indexes?
<br>
'''A:''' The answer is no. Linear data structures are used when the programmer does not know how many elements of an array there are going to be overall(assuming arrays are used over linear data structures)by the end of the programs termination. The problem that arises with using arrays when the number of elements is unknown is that dynamic allocation, copying and deletion need to be preformed every time a new element is added, altered or deleted in a sequence of data. In order to keep an index of the Nodes (in a linear data structure) a dynamic array would have to be made with a number to signify the artificial index of the linear data structure Node. The programmer could then refer to an index of the array that will automatically loop through the linear data structure (via a code block) to give a result. This would defeat the purpose of a linear data structure because the array holding the indexes would have to be deleted and reallocated every time the linear data structure changes.
 
Example explanation: A stack has numbers 15 10 5 on it and an array allocated to 3 indexes (with values 0, 1, 2) to match the number of Nodes. If a person adds 1 more data to the Stack (push(20))then the array would have to be deleted and reallocated, defeating the purpose of the stack in the first place.
<br>'''Submitted by:''' Team 6 <br><br>

Navigation menu