Data Structures using C Part 3 - Stack algorithms | Stack operations | Stack algorithms
Stack algorithm and stack operations : Stack algorithms : The concept of an algorithm is the basic need of any programming development in computer science. An algorithm is a method of defining steps in solving a problem. an algorithm is a sequence of computational steps that transforms input(s) into output(s). An algorithm to add two numbers entered by user: Step 1: Start Step 2: Declare variables num1, num2 and sum. Step 3: Read values num1 and num2. Step 4: Add num1 and num2 and assign the result to sum. sum = num1+num2 Step 5: Display sum Step 6: Stop Algorithms of Stack operations : Algorithms of PUSH operations Step 1: Start Step 2: Checks if the stack is full if(top==(SIZE-1)) Step 3: If the stack is full, Give a message and exit printf("\nStack Overflow"); Step 4: If the stack is not full, increment top to point next empty space. top=top+1; Step 5: Add data element to the stack location, where top is pointing. printf("\nEnter the item to be pushed in stack:"); stack[top]=item; Step 6: Stop Algorithms of POP operations : Step 1: Start Step 2: Checks if the stack is empty if(top==-1) Step 3: If the stack is empty, Give a message and exit printf("\nStack Underflow"); Step 4: If the stack is not empty, Print the element at which top is pointing. printf("\nPopped element is : %d\n",stack[top]); Step 5: Decrement top to point previous location . top=top-1; Step 6: Stop Some of the practical applications of stack: Undo operation (generally in editors, drawing app). To reverse a String. Parsing in Compilers. Conversions of Expressions. Expressions Evaluation. Conversions of Expressions Algebraic Expressions : An algebraic expression is a legal combination of operators and operands. For Example : (a+b)+(c*d) Expressions’ notations An algebraic expression can be represented using three different notations. Infix: It is the form of an arithmetic expression in which we fix (place) the arithmetic operator in between the two operands A + B Prefix: + A B Postfix: A B + Conversions of Expressions : We can convert an Expression from infix to Prefix OR Postfix by making use of Stacks. WHY ? It is easy for us humans to read and write expressions in infix notation but computers can not. An algorithm to process infix notation could be difficult and costly in terms of time and space consumption. Priority of Operators : When several operations occur in an expression, each part is evaluated and resolved based on the priority assigned to the operators. The operator with highest priority is evaluated before the operator with lowest priority. 1 ( ) { } [ ] 2 Exponent ^ 3 / * 4 + - infix, prefix & postfix : prefix + A B + A B C * + A B C /+ AB - CD + / AB / CD - * + ABCD infix A + B A + B - C (A + B) * C (A + B) / (C - D) A / B + C / D ((A B + C * ) - D postfix AB + AB + C - AB + C * AB + CD- / AB/ CD/ + A B + C * D - Detailed explanation of Stack operations Applications of Stack ankpro ankpro training Asp.net MVC C# C sharp Bangalore Rajajinagar Selenium Coded UI Mobile automation testing Mobile testing JQuery JavaScript .Net C C++ Components of the .Net framework Hello World Literal Keywords Variable Data types Operators Branching Loops Arrays Strings Structures Enums Functions
Download
1 formatsVideo Formats
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.