Back to Browse

Stack Using Array in Data Structure Using C Programming Language

35 views
Jun 26, 2021
59:28

The stack is member of linear data structure and works as the rule of Last In First out(LIFO). In other word we can say that only one ends of the list their inserting and deleting element of list is possible. Thus, we can say that stack is restrict list. Stack is a very useful linear data structure. Many concepts use this algorithm to implement their process. Like recursion, conversion of infix , postfix and prefix expression operations also use operating system to maintain their functioning. A stack is a linear data structure in which addition new element at top of the stack like plates pile at hotel. Every new plate added to the pile and every new plate taken also at same end, means top of the stack and that is deletion of plate at same end. General linear data structure such as an array and linked list allows us to insert and delete an element at any place in the list, either at the beginning or at the end or even in the middle of the list, but in stack is restrict data structure. Thus we can addition and deletion element at same place, not allows us to addition or deletion element at middle of the list. We are comparing stack with like one room has only one door for enter and exit to person. The stack is also called push-down list. Real life practical example of Stack as given below : 1. Pile of plates at hotel or our home 2. An old newspapers pile at our home 3. Pile of books at library 4. A new CD/DVD rack at any shop of computer 5. A railway bogies shunting 6. Post card arranging at our home 7. The tennis balls in their container 8. The files pile up in the tray 5.2.1 Definition : 1. When we can insert and delete only one end it is called stack. 2. A stack is a linear data structure in which addition of new element and deletion of an existing element always takes place at the same end. This end is often known as top of the stack. 3. If any list only one entry and one exit, that is known as stack. Like any room only one door for entry and exit. Stack is a ADT. Abstract Data Type. Operations on stack : There are main four operations apply on stack as following : 1. Push : Insert element into the stack that is known as push operation. 2. Pop : Delete element into the stack that is known as pop operation. 3. Peep : Search element into the stack that is known as peep operation. 4. Display/Show : Display all element of stack that is known as show or display operation. Other Term of stack : 1. Top : Top most elements in the stack that is known as top. 2. Underflow : Not any value in the list or array or stack or queue or linked list that is known as underflow. Example : if stack is underflow than top=-1 value it can hold. 3. Overflow : overflow means out of range value in list or stack or queue. Example : if stack is overflow than top value is equal to no. of element(maximum size) top=n. There are two techniques implement to stack as given below : 1. Implementation of stack using arrays 2. Implementation of stack using linked list Implementation of stacks using arrays : Array can be used to represent stack, it is very easy if we represent using array but problem is using array that we provide fixed size of array at beginning of array declaration, so care should be exercises that take size of array. An array is a data structure that can store a fixed number of elements. We can give maximum size of array when declaration time of array and Initialize top variable to -1 value, declare fixed size of an array. Example : declare array st[5] and top as integer data type. First initialize top=-1 St[5]={4,6,8,10,12}; Beginning not any value in array that time top value is -1 and after insert one element at 0th position top of the stack as shown below figure : top=0 top=1 top=2 index element 4 3 2 1 0 4 index element 4 3 2 8 1 6 0 4 index element 4 3 2 1 6 0 4 top=3 top=4 index element 4 3 10 2 8 1 6 0 4 index element 4 12 3 10 2 8 1 6 0 4 Now stack is full. If you can try inserting more element than resize you stack array otherwise give message ‘Stack is overflow’. On we can perform deletion of element in stack at same end. This is shown below figure : Top=3 top=2 top=1 index element 4 3 10 2 8 1 6 0 4 index element 4 3 2 8 1 6 0 4 Index element 4 3 2 1 6 0 4 index element 4 3 2 1 0 4 Top=0 top=-1 index element 4 3 2 1 0

Download

0 formats

No download links available.

Stack Using Array in Data Structure Using C Programming Language | NatokHD