Archive

Posts Tagged ‘stack’

Implementation of algorithms (without recursion) for preorder & level-order traversal of binary trees.

March 31, 2011 Leave a comment

The iterative (non-recursive) function preorderTreeTraverse() can perform preorder traversing of a binary tree with the help of a stack that can hold pointers to nodes of the tree.

Also, the iterative (non-recursive) function layerTreeTraverse() can perform level-order traversing of a binary tree with the help of a queue that can hold pointers to nodes of the tree.

Read more…

Implementation of algorithm for converting an expression from infix to postfix notation.

March 26, 2011 Leave a comment

The following program converts an expression from infix to postfix notation. The conversion is carried out with the help of a stack. For example, to turn the expression (A + B) into the postfix form A B +, we ignore the left parenthesis, convert the A to postfix form, we store the + operator on the stack, we convert B to postfix form and then, when find the right parenthesis, we pop the + operator from the top of the stack. In particular, the following implementation works only for the addition and multiplication of integers.

Read more…

Implementation of algorithm for calculating a postfix expression.

March 24, 2011 Leave a comment

The following program reads any postfix expression that includes integer multiplication and addition, evaluates the expression and displays the final result on the screen. The program stores the intermediate results in a stack of integers.

The terms (operands) are pushed onto the stack. The operators are applied to the two entries at the top of the stack (the two entries are popped from the stack); the result is pushed back into the stack. Because the order in which the two pop() functions are performed in the expression of this code is not specified in C++, the code for some non-commutative operators, such as the ones for subtraction and division, would be somewhat more complicated.

Read more…

Arduino: A library for implementing a generic, dynamic stack (linked list version).

September 25, 2010 Leave a comment

This project refers to an Arduino library implementing a generic, dynamic stack (linked list version).

The data structure is implemented as a class in C++.

For more information, you can get the project itself ‘StackList‘.

Arduino: A library for implementing a generic, dynamic stack (array version).

September 23, 2010 Leave a comment

This project refers to an Arduino library implementing a generic, dynamic stack (array version).

The data structure is implemented as a class in C++.

For more information, you can get the project itself ‘StackArray‘.

Arduino: Valuation calculator of infix mathematical expressions.

September 18, 2010 Leave a comment

This project refers to an Arduino sketch that implements a calculator which valuates infix mathematical expressions using appropriate algorithms and data structures. The mathematical expressions are given through the USB port, while the valuation and presentation of results is done by Arduino. The results are displayed in an appropriate LCD display.

Read more…