What is the importance of Linked lists, Stacks, and Queues (in c++) ??
As far as I know in Java,For classes such as stacks that implement collections of objects, an important objective is to ensure that the amount of space used is always proprtional to the number of items in the collection.In a stack,When u click a hyperlink, your browser displays the new page . u can keep clicking on hyperlinks to visit new pages. u can always revisit the previous page by clicking the back button
They have another use as well. These types of structures can also be used to enforce certain logic on the program. So, for example - if you were writing a browser history a stack would be a good idea because the primary operations are going to be push/pop. In theory, each type of data structure should also have some optimizations for whatever operations it uses most frequently. For example, a Stack will likely be implemented as a linked collection of nodes since - under that design - push and pop are very inexpensive operations.
thanks; i was wondering why these when arrays are available.
Arrays are primitive collections. Vectors in C++ are enhanced arrays. Stacks and queues are data types that are implemented with either arrays or vectors. Stacks are LIFO (Last In First Out) structures. Queues are FIFO (First In First Out). Stacks are like a stack of dishes, the last one was put on the top of the stack, and it'll be the first one that you grab. Queues are like waiting in line, the first person in line is the first person served (dequeued). Linked lists are just datum strewn around memory, but have the address of the next datum in a wrapper to link the datum into a list.
Join our real-time social learning platform and learn together with your friends!