Professional Documents
Culture Documents
COM
HOM E
TUTOR IA LS
PR OG R A M M ING LECTUR ES
PR OG R A M M ING BOOKS
S OUR CE CODE
F OR UM S
JOIN US
Search
Ads by Google
C++ Stack C
CATEGOR IES
PHP Programming Resources C/C++ Programming Resources JAVA Programming Resources .NET Programming Resources Android Programming Resources iPhone Programming Resources
Stacks in C++
L EAVE A C O MMENT
Stack is an ordered group of homogeneous items. Items are added to and removed from the top of the stack (the most recently added items are at the top of the stack). last item to be added is the first to be The removed (LIFO: Last In, First Out). A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted at one end called the TOP of the stack. The implementation of stack provides for the insertion and deletion of items (at run time), so that a stack is a dynamic, constantly changing object.
R ECENT POS TS
Navigation Bar Controller iPhone Development Using View Controller iPhone Development UIKit Views and Animation iPhone Development Views and Drawing iPhone Development Model View Controller (MVC) iPhone Development
Applications of Stack in data structures 1864 view(s) File Handling using Input-Output Streams in Java 1580 view(s) Advanced Java Tutorial (For Intermediate) 1348 view(s) Attendance Management System 1230 view(s) String Manipulation in Java 1008 view(s) JAVA Graphical User Interface (GUI) 974 view(s) Sockets and Network Programming in Java 917 view(s)
How does a stack change? items may be put on top of the stack. In which case the top of the stack New moves upward to correspond to the new highest element. Items which are at the top of the stack may be removed. In which case the top of the stack moves downward to correspond to the new highest element.
sourcecodemania.com/stacks-in-cpp/
1/6
9/13/12 Stacks in C++ | C/c++ Programming Resources | Source Code Mania.COM Circular Linked Lists 914 view(s) UDP Datagram Sockets in Java 891 view(s) Advanced Data Structures Tutorial using C++ 805 view(s)
Which end is top? We must decide which end of the stack is designated as its top. common data A structure in computing. items are popped and pushed (retrieved and stored) from the top of the Data stack. Stacks normally have a maximum size. It is an error to push items onto a full stack, or pop items off an empty stack.
Applications of Stack
Parsing of algebraic expression Banking Transaction View (You view the last transaction first)
TAGS
C-Sharp
CSS Data
structures
iPhone
JAVA Java
JAVA GUI
Collections
JavaScript Mobile
Programming Books
PDF PHP pointers
Object Oriented
Programming
Operations on Stack
A Stack normally has the following methods: push(item) pop( ) isEmpty() isFull() top( ) //Push an item onto the stack //Pop the top item off the stack //Return true if stack is empty // Return true if stack is full //Return value of top item
How do we know that which element to pop when user asks a pop operation. As not all the spaces of array
sourcecodemania.com/stacks-in-cpp/ 2/6
are filled. e need another variable (usually Int) to keep track of last pushed index. for each push we add W So one to top and for each pop we deduct one from top. A [0] B [1] [2] [3]
What if the stack is full or what if the stack is empty? Solution: Before any push check if the stack is already filled or not. If it is filled then generate error message e.g Stack Overflow. Before pop check if stack is not already empty
#nld<oi.> icuecnoh #nld <otemh icue isra.> #eielnt 1 dfn egh 0 ittp-; n o=1 itsaklnt] n tc[egh; vi mi( od an) { itc; n h d{ o cu < ed < ":ps" ot < nl < 1 uh; cu < ed < ":pp; ot < nl < 2 o" cu < ed < ":ei" ot < nl < 3 xt; cu < ed < "ne coc" ot < nl < etr hie; cn> c; i > h sic(h wthc) { cs 1 ae : ps(; uh) lsSak) ittc(; bek ra; cs 2 ae : cu < "aappd "< pp) ot < dt oe= < o(; lsSak) ittc(; bek ra; cs 3ei() ae :xt0; } }wie1; hl() gth) ec(; } vi ps(n dt) od uhit aa { i(o+=lnt) ftp1=egh { cu < "tc oefo\ Cno etrnwdt" ot < sak vrlwn ant ne e aa; rtr; eun } tp+ o+; saktp=aa tc[o]dt;
3/6
4 3 4 4 4 5 4 6 4 7 4 8 4 9 5 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 6 0 6 1 6 2 6 3
} itpp) n o( { ittmVr n epa; i(o=-)/ecnas mk iEpy) ftp=1/w a lo ae smt( { cu < "tc i udrlw(mt); ot < sak s nefo Epy" rtr(1; eun-) } tmVr=saktp; epa tc[o] tpo-; rtr tmVr eun epa; } vi lsSak) od ittc( { cu < ed < "h saki"< ed ; ot < nl < Te tc s < nl frititpi=;-) o(n =o;>0icu < saki < ed; ot < tc[] < nl }
W e want to ensure that parenthesis are nested correctly and the expression is valid. Validation 1. There is an equal number of right and left parentheses 2. Every right parenthesis is preceded by a matching left parenthesis Expressions
( B +)*C Vld A ai A +B Ivld ) nai (+] Ivld AB nai
Rules Each left parentheses is the opening scope Each right parenthesis is a closing scope Parentheses count = 0 at the end means that no scopes have been left open and left and right parentheses exactly match. parentheses count at any time should never become negative. IF negative then it means The expression is invalid.
Related Posts
The OpenGL Programming Guide Introduction to Recursion in C++ Functions with parameters in C++ Functions in C++ Repetition Control Statements in C++ C++ Expressions and Language Constructs Introduction to C++ Basics Mobile Developers Guide to the Parallel Universe Silverlight for Windows Phone Object-oriented Programming in C# for C and Java programmers
Tagged with: C/C++ language Data structures
Ads by Google
C++
Stack
C Source Code
sourcecodemania.com/stacks-in-cpp/
4/6
Leave a Reply
Your email address will not be published. Name
Website
Comment
Post Comment
V IS IT OUR FR IENDS !
AR CHIV ES
Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!
July 2012 June 2012 May 2012 February 2012 January 2012 December 2011 November 2011 October 2011 September 2011 August 2011
Please install and activate the "Twitter for WordPress" plugin to use this section.
sourcecodemania.com/stacks-in-cpp/
5/6
PA G ES
THE LA TES T
M OR E
Thanks for dropping by! Feel free to join the discussion by leaving comments, and stay updated by subscribing to the RSS feed.
sourcecodemania.com/stacks-in-cpp/
6/6