473,508 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stack Implementation Code

Expression Evaluation in Post-Fix Notation Using Stack
=====================

/*
This program has been made by Ashif Zubair.
Roll # 1468, B.Sc.(Hons.) in C.S.
ALL RIGHTS ARE RESERVED TO ASHIF ZUBAIR.
PROGRAM OBJECTIVE :-

*/
#include <iostream.h>
#include <conio.h>

class stack
{
private:
char *sspace;
int tos;
public:
stack();
int ssize;
void push(char);
char pop();
int isempty();
int isfull();
}stk;

/* Class Functions */
stack::stack()
{
clrscr();
tos = -1;
cout<<"Enter Stack Size : ";
cin>>ssize;
clrscr();
}

void stack::push(char ch)
{
if(!isfull())
{
tos++;
sspace[tos] = ch;
}
}

char stack::pop()
{
if(!isempty())
{
char ch;
ch = sspace[tos--];
return ch;
}
}

int stack::isfull()
{
if(tos > ssize)
return 1;
else
return 0;
}

int stack::isempty()
{
if(tos == -1)
return 1;
else
return 0;
}
/* Class Functions Finished */
/* Main Function */

void main (void)
{
clrscr();
char exp[100];
char get=NULL;
char temp=NULL;
int i=0;
int open = 0;
int close = 0;
int high = 0;
cout<<"Enter Your Expression :\nPress x Key When Finished\n\t\t\t";
while(get != 'x'|| get != 'X')
{
get = getche();
switch(get)
{
case '0' :
exp[i++] = get;
break;
case '1' :
exp[i++] = get;
break;
case '2' :
exp[i++] = get;
break;
case '3' :
exp[i++] = get;
break;
case '4' :
exp[i++] = get;
break;
case '5' :
exp[i++] = get;
break;
case '6' :
exp[i++] = get;
break;
case '7' :
exp[i++] = get;
break;
case '8' :
exp[i++] = get;
break;
case '9' :
exp[i++] = get;
break;
case '(' :
open++;
stk.push(get);
break;
case ')' :
close++;
temp = stk.pop();
while(temp != '(')
{
exp[i++] = temp;
temp = stk.pop();
}

case '^' :
stk.push(get);
high++;
break;
case '/' :
stk.push(get);
high++;
break;
case '*' :
stk.push(get);
high++;
break;
case '%' :
stk.push(get);
high++;
break;

case '+' :
if(high == 0)
stk.push(get);
else
while(!stk.isempty())
{
temp = stk.pop();
if(temp != ')' || temp != '(')
exp[i++] = temp;
}
high = 0;
break;
case '-' :
if(high == 0)
stk.push(get);
else
while(!stk.isempty())
{
temp = stk.pop();
if(temp != ')' || temp != '(')
exp[i++] = temp;
}
high = 0;
break;
default:
cout<<"\n\nUnknow Operand/Operator\nOnly 0-9 & *,/,%,+,- Keys
Allowed\n\nContinue To input : ";
}
cout<<"\n\n"<<exp[i-1]<<"\t"<<i<<endl;
}
clrscr();
cout<<"Your Given Equaation in POST-FIX Representation.\n\n";
for(int loop = 0;loop<i; loop++)
{
cout<<exp[loop];
}
getch();
}

/*=======================*/

Jul 23 '05 #1
2 4003
I assume we can just guess as to what your question is... Have you
even tried to compile this code yet?

Jul 23 '05 #2
its a functional code, i've posted the code jsut to share it, and any
enhancement i could get from the viewrs comments!

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
5003
by: Jonas Rundberg | last post by:
Hi I just started with c++ and I'm a little bit confused where stuff go... Assume we have a class: class test { private: int arr; };
4
2612
by: Chris Mabee | last post by:
Hello all, and Merry Christmas, I'm having a problem understanding an example of an array based implementation of a stack in a textbook of mine. The code in question is written below. The syntax...
10
8295
by: Shuo Xiang | last post by:
Greetings: I know that variables declared on a stack definitely does not reside in heap space so there is only a very limited amount of stuff that you can store in the stack of a function. But...
20
3448
by: Sushil | last post by:
Hi gurus I was reading FAQ "alloca cannot be written portably, and is difficult to implement on machines without a conventional stack." I understand that the standard does not mandate...
4
3598
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
16
4421
by: sarathy | last post by:
Hi all, I need a few clarifications regarding memory allocaion in C++. I apologize for the lengthy explanation. 1. In C++, Objects are allocated in heap. What does heap refer to? Is it an area...
9
3143
by: Roman Mashak | last post by:
Hello, I'm confused about heap and stack memories management in C language. Most books explain that local stack variables for each function are automatically allocated when function starts and...
3
2919
by: NewLine | last post by:
Hi If I have a function: std::vector<intmy_rbv() { std::vector<intx; // some stuff return x; }
87
5464
by: CJ | last post by:
Hello: We know that C programs are often vulnerable to buffer overflows which overwrite the stack. But my question is: Why does C insist on storing local variables on the stack in the first...
62
2785
by: jt | last post by:
hello everyone.. int fun() { /* anything */ } int main(void) { fun(); }
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.