CEG's Linux User Group

  • Increase font size
  • Default font size
  • Decrease font size
Home Labs
Labs

Balancing parenthesis

E-mail Print
User Rating: / 7
PoorBest 

BALANCING PARENTHESIS

Introduction:

Balancing parenthesis is one of the most common application of stack. The expression is got an input from the user. Then each char is examined. If the character is a opening parenthesis, then it is pushed into the stack. If the character is a closing parenthesis, we pop the top element from the stack and check if it makes a valid couple of brackets with the examined element.

If this is not the case, the series is not balanced, otherwise we can discard both parenthesis and go on with the next character, until the series is over.

When there are no parenthesis left to examine, if the stack is empty then the expression is valid; if there are still elements on the stack we can conclude that the series is unbalanced.

Last Updated on Saturday, 06 June 2009 19:13 Read more...
 

Postfix evaluation

E-mail Print
User Rating: / 8
PoorBest 

POSTFIX EVALUATION

Introduction :

Calculators employing reverse Polish notation use a stack structure to hold values. Expressions can be represented in prefix, postfix or infix notations. Conversion from one form of the expression to another form needs a stack. Many compilers use a stack for parsing the syntax of expressions, program blocks etc. before translating into low level code. Most of the programming languages are allowing them to be parsed with stack based machines. Consider the following expression ((1+2)*4)+ 3 can be written down like this in postfix notation with the advantage of no precedence rules and parentheses needed:
1 2 + 4 * 3 +
Last Updated on Saturday, 06 June 2009 19:52 Read more...
 

Reversing a string using stack

E-mail Print
User Rating: / 8
PoorBest 

REVERSING A STRING USING STACK

 

Introduction :

In computer science, data structure is a particular way of sorting and organizing data in the computer so that it can be used efficiently. The implementation of a data structure usually requires writing a set of procedures that create and manipulate instances of that structure. The efficiency of a data structure cannot be analyzed separately from those operations. A stack is an abstract data type and data structure based on the principle of Last In First Out(LIFO). There are two main operations: push and pop. The push operation adds (stores) to the list. Due to practical memory limits, stacks are often of a particular size, so this operation must check that the stack is not full, otherwise it will fail. The pop operation removes (deletes) an item from the list, AND returns or exports this item value to the calling program. The pop operation must check to see if the stack is not empty, otherwise it will fail.

Last Updated on Friday, 05 June 2009 15:50 Read more...
 

Stack Implementation Using Templates

E-mail Print
User Rating: / 4
PoorBest 

Templates:

C++ templates enable generic programming. C++ supports both function and class templates. Templates may be parameterized by types, compile-time constants, and other templates. C++ templates are implemented by instantiation at compile-time. To instantiate a template, compilers substitute specific arguments for a template's parameters to generate a concrete function or class instance. Templates are a powerful tool that can be used for generic programming, template metaprogramming, and code optimization, but this power implies a cost. Template use may increase code size, since each template instantiation produces a copy of the template code: one for each set of template arguments. This is in contrast to run-time generics seen in other languages (e.g. Java) where at compile-time the type is erased and a single template body is preserved.

Last Updated on Sunday, 17 May 2009 11:25 Read more...
 


Page 4 of 4