JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label Linked-list-implementation-of-stack. Show all posts
Showing posts with label Linked-list-implementation-of-stack. Show all posts

Linked list implementation of stack

10:42 PM
Linked list implementation of stack Instead of using array, we can also use linked list to implement stack. Linked list allocates the memory dynamically. However, time complexity in both the scenario is same for all the operations i.e. push, pop and peek. In linked list implementation of stack, the nodes are maintained non-contiguously in the memory. Each node contains a pointer to its immediate successor node in the stack. Stack is said to be overflown if the space left in the memory heap is not enough to create a node. The top most node in the stack always contains null in its address field. Lets discuss the way in which, each operation is performed in linked list implementation of stack. Adding a node to the stack (Push operation) Adding a node to the stack is referred to as  push  operation. Pushing an element to a stack in linked list implementation is different from that of an array implementation. In order to push an element onto the stack, the following steps ...

.