Sponsored Content
Full Discussion: Runtime error in my code...
Top Forums Programming Runtime error in my code... Post 302513998 by poonam.gaigole on Thursday 14th of April 2011 01:15:36 PM
Old 04-14-2011
Runtime error in my code...

INFIX TO POSTFIX CONVERSION :

Code:
//Convert an infix expression to postfix expression...

#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
char ifx[50],pfx[50],stk[50];
int top=-1,n;
void push(char ch)
{
    if(top!=n-1)
    {
        top++;
        stk[top]=ch;
    }
    else
        cout<<"\nThe stack is full.";    
}
char pop()
{
    char rmv;
    if(top!=-1)
    {
        rmv=stk[top];
        top--;
        return rmv;
    }
    else
        return '#';
}
char topele()
{
    char ch;
    if(top==-1)
    {
        ch='#';
        return ch;
    }   
    else
        ch=stk[top];
}
int chkpres(char ch)
{
    ch=topele();
    switch(ch)
    {
        case '^':return 7;
            break;
        case '/':return 6;
            break;
        case '*':return 5;
            break;
        case '+':return 4;
            break;
        case '-':return 3;
            break;
        default:return 0;
            break; 
     } 
}                 
/*int braces(char *s)
{
    int lftbr,rgtbr=0;
    for(int i=0;s[i];++i)
    {
        if(s[i]=='(')
            lftbr++;
        else
            rgtbr++;
    }
    if(lftbr==rgtbr)
        return 0;
    else if(lftbr<rgtbr)
        return 1;
    else return -1;
}*/
int main()
{
    char ele,elem,chk,popp,topp;
    int pre,pres;
    cout<<"\nEnter how many elements you want to enter in the infix expression: ";
    cin>>n;
    cout<<"\nEnter the infix expression: ";
    for(int i=0;i<n;++i)
        cin>>ifx[i]; 
    topp=topele();
    strcpy(pfx," ");
    for(int i=0,j=0;ifx[i]!='\0',pfx[j]!='\0';++i,++j)
    {
        ele=ifx[i];
        if(ele!='^' && ele!='*' && ele!='/' && ele!='+' && ele!='-')
            pfx[j++]=ifx[i];
        else if(ele=='^'||ele=='*'||ele=='/'||ele=='+'||ele=='-')
        {
            if(topp=='^'||topp=='*'||topp=='/'||topp=='+'||topp=='-')
            {
                pre=chkpres(ele);
                pres=chkpres(topp);
                if(pre>pres)
                {
                    push(pre);
                    top++;
                }
                else if(pre<=pres)
                    pfx[j++]=pres;
            }    
            else
            {
                push(ele);
                topp=ele;
            }
        }
        else if(ele=='(')
        {
            i++;
        }
        else if(ele==')')
        {
            while(topp!='#')
            {
                popp=topp;
                pfx[i]=popp;
            }
        }
        cout<<"---------------"<<pfx[j++];
    }
    cout<<"\nThe postfix expression is: ";
    for(int i=0;pfx[i]!='\0';++i)
    {
        cout<<pfx[i];
    }
    cout<<endl;
return 0;
}

 

9 More Discussions You Might Find Interesting

1. Solaris

Runtime error...

My interprise use a UNIX mainform for a instrumentation process control. The control use the FOXBORO INVENSYS system and they donīt gonna solve the problem the run time error. The run time error happen without logic explication. When everything itīs run perfectely and happenly appears the run time... (1 Reply)
Discussion started by: marpin
1 Replies

2. UNIX for Dummies Questions & Answers

Runtime Error...

My system did stay appears the error Run Time Library Error. What itīs? When the error appear, iīve to reboot my system and lost all I did. Is there the UNIX System problem? Please. I need help!!! (4 Replies)
Discussion started by: marpin
4 Replies

3. Solaris

Re:How to get the path during runtime?

Thank u vgesh99 It works well.. (1 Reply)
Discussion started by: Nandagopal
1 Replies

4. Programming

Runtime error in C++ Program - Help

All, I am getting this when i try to ran a program in HP unix. Things i came across 1. i have a system HP-UNIX where this same exe is working. 2. We have set a new HP_UNIX with the same configration and copied the exe to the new system we are getting this error. 3. Only... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

5. Shell Programming and Scripting

error code 137 and error code 35072

Hi while trying to run few scripts /afs/ae.ge.com/informatica/ardw/dev/bin/cdw_ar_update_recvbal.sh this script contains the below data load_dir=/afs/ae.ge.com/informatica/ardw/dev/data prog_dir=/afs/ae.ge.com/informatica/ardw/dev/bin ctl_dir=/afs/ae.ge.com/informatica/ardw/dev/ctl... (1 Reply)
Discussion started by: laxmi131
1 Replies

6. Programming

Help... runtime error in my maxheap sort program

#include<iostream> using namespace std; int *a,size,heapsize; void maxheap(int *a,int j) { int l,r,largest,temp; l=2*j; r=(2*j)+1; for(j=0;j<size;++j) { if(l<=heapsize && a>a) largest=l; else largest=j; if(r<=heapsize... (5 Replies)
Discussion started by: poonam.gaigole
5 Replies

7. UNIX for Dummies Questions & Answers

No Java runtime environment (JRE) error

Hi all, I am trying to install a .bin file for that it requires IBMJava2-AMD64-142-JRE-1.4.2-13.8.x86_64.rpm to be installed. I have installed this rpm but when i try to install .bin file, it complains that no JRE found. How to solve this. Thanks in advance! #... (0 Replies)
Discussion started by: lramsb4u
0 Replies

8. Programming

Fortran runtime error: Insufficient data descriptors in format after reversion

Hello, I have some Fortran code that is providing the following error: At line 1165 of lapc_shells_2.f Fortran runtime error: Insufficient data descriptors in format after reversion Here are the lines just above and including 1165: WRITE (*,"('ATTEMPTING TO READ PLATE... (1 Reply)
Discussion started by: jm4smtddd
1 Replies

9. Red Hat

Runtime Error Enable user directory apache

Hi I am exactly according to this link CentOS 6 - Apache httpd - Enable Userdir : Server World I Enabled userDirectory Server version: Apache/2.2.15 CentOS release 6.8 (Final) But Iget this Error Forbidden You don't have permission to access /~mn/index.html on this server Goal... (2 Replies)
Discussion started by: mnnn
2 Replies
std::stack< _Tp, _Sequence >(3) 			     Library Functions Manual				   std::stack< _Tp, _Sequence >(3)

NAME
std::stack< _Tp, _Sequence > - SYNOPSIS
Public Types typedef _Sequence::const_reference const_reference typedef _Sequence container_type typedef _Sequence::reference reference typedef _Sequence::size_type size_type typedef _Sequence::value_type value_type Public Member Functions stack (const _Sequence &__c) template<typename... _Args> void emplace (_Args &&...__args) void noexcept (noexcept(swap(c, __s.c))) void pop () void push (const value_type &__x) void push (value_type &&__x) size_type size () const reference top () const_reference top () const Public Attributes __pad0__: c(std::move(__c)) { } bool empty() const { return c.empty() Protected Attributes _Sequence c Friends template<typename _Tp1 , typename _Seq1 > bool operator< (const stack< _Tp1, _Seq1 > &, const stack< _Tp1, _Seq1 > &) template<typename _Tp1 , typename _Seq1 > bool operator== (const stack< _Tp1, _Seq1 > &, const stack< _Tp1, _Seq1 > &) Detailed Description template<typename _Tp, typename _Sequence = deque<_Tp>>class std::stack< _Tp, _Sequence > A standard container giving FILO behavior. Template Parameters: _Tp Type of element. _Sequence Type of underlying sequence, defaults to deque<_Tp>. Meets many of the requirements of a container, but does not define anything to do with iterators. Very few of the other standard container interfaces are defined. This is not a true container, but an adaptor. It holds another container, and provides a wrapper interface to that container. The wrapper is what enforces strict first-in-last-out stack behavior. The second template parameter defines the type of the underlying sequence/container. It defaults to std::deque, but it can be any type that supports back, push_back, and pop_front, such as std::list, std::vector, or an appropriate user-defined type. Members not found in normal containers are container_type, which is a typedef for the second Sequence parameter, and push, pop, and top, which are standard stack/FILO operations. Definition at line 96 of file stl_stack.h. Constructor &; Destructor Documentation template<typename _Tp, typename _Sequence = deque<_Tp>> std::stack< _Tp, _Sequence >::stack (const _Sequence &__c) [inline], [explicit] Default constructor creates no elements. Definition at line 134 of file stl_stack.h. Member Function Documentation template<typename _Tp, typename _Sequence = deque<_Tp>> void std::stack< _Tp, _Sequence >::pop () [inline] Removes first element. This is a typical stack operation. It shrinks the stack by one. The time complexity of the operation depends on the underlying sequence. Note that no data is returned, and if the first element's data is needed, it should be retrieved before pop() is called. Definition at line 212 of file stl_stack.h. template<typename _Tp, typename _Sequence = deque<_Tp>> void std::stack< _Tp, _Sequence >::push (const value_type &__x) [inline] Add data to the top of the stack. Parameters: __x Data to be added. This is a typical stack operation. The function creates an element at the top of the stack and assigns the given data to it. The time complexity of the operation depends on the underlying sequence. Definition at line 186 of file stl_stack.h. template<typename _Tp, typename _Sequence = deque<_Tp>> size_type std::stack< _Tp, _Sequence >::size () const [inline] Returns the number of elements in the stack. Definition at line 151 of file stl_stack.h. template<typename _Tp, typename _Sequence = deque<_Tp>> reference std::stack< _Tp, _Sequence >::top () [inline] Returns a read/write reference to the data at the first element of the stack. Definition at line 159 of file stl_stack.h. template<typename _Tp, typename _Sequence = deque<_Tp>> const_reference std::stack< _Tp, _Sequence >::top () const [inline] Returns a read-only (constant) reference to the data at the first element of the stack. Definition at line 170 of file stl_stack.h. Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Tue Jun 10 2014 std::stack< _Tp, _Sequence >(3)
All times are GMT -4. The time now is 01:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy