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
Graphics::Primitive::Component(3pm)			User Contributed Perl Documentation		       Graphics::Primitive::Component(3pm)

NAME
Graphics::Primitive::Component - Base graphical unit DESCRIPTION
A Component is an entity with a graphical representation. SYNOPSIS
my $c = Graphics::Primitive::Component->new({ origin => Geometry::Primitive::Point->new({ x => $x, y => $y }), width => 500, height => 350 }); LIFECYCLE
prepare Most components do the majority of their setup in the prepare. The goal of prepare is to establish it's minimum height and width so that it can be properly positioned by a layout manager. $driver->prepare($comp); layout This is not a method of Component, but a phase introduced by the use of Layout::Manager. If the component is a container then each of it's child components (even the containers) will be positioned according to the minimum height and width determined during prepare. Different layout manager implementations have different rules, so consult the documentation for each for details. After this phase has completed the origin, height and width should be set for all components. $lm->do_layout($comp); finalize This final phase provides and opportunity for the component to do any final changes to it's internals before being passed to a driver for drawing. An example might be a component that draws a fleuron at it's extremities. Since the final height and width isn't known until this phase, it was impossible for it to position these internal components until now. It may even defer creation of this components until now. It is not ok to defer all action to the finalize phase. If you do not establish a minimum hieght and width during prepare then the layout manager may not provide you with enough space to draw. $driver->finalize($comp); draw Handled by Graphics::Primitive::Driver. $driver->draw($comp); METHODS
Constructor new Creates a new Component. Instance Methods background_color Set this component's background color. border Set this component's border, which should be an instance of Border. callback Optional callback that is fired at the beginning of the "finalize" phase. This allows you to add some sort of custom code that can modify the component just before it is rendered. The only argument is the component itself. Note that changing the position or the dimensions of the component will not re-layout the scene. You may have weird results of you manipulate the component's dimensions here. class Set/Get this component's class, which is an abitrary string. Graphics::Primitive has no internal use for this attribute but provides it for outside use. color Set this component's foreground color. fire_callback Method to execute this component's "callback". get_tree Get a tree for this component. Since components are -- by definiton -- leaf nodes, this tree will only have the one member at it's root. has_callback Predicate that tells if this component has a "callback". height Set this component's height. inside_bounding_box Returns a Rectangle that defines the edges of the 'inside' box for this component. This box is relative to the origin of the component. inside_height Get the height available in this container after taking away space for padding, margin and borders. inside_width Get the width available in this container after taking away space for padding, margin and borders. margins Set this component's margins, which should be an instance of Insets. Margins are the space outside the component's bounding box, as in CSS. The margins should be outside the border. maximum_height Set/Get this component's maximum height. Used to inform a layout manager. maximum_width Set/Get this component's maximum width. Used to inform a layout manager. minimum_height Set/Get this component's minimum height. Used to inform a layout manager. minimum_inside_height Get the minimum height available in this container after taking away space for padding, margin and borders. minimum_inside_width Get the minimum width available in this container after taking away space for padding, margin and borders. minimum_width Set/Get this component's minimum width. Used to inform a layout manager. name Set this component's name. This is not required, but may inform consumers of a component. Pay attention to that library's documentation. origin Set/Get the origin point for this component. outside_height Get the height consumed by padding, margin and borders. outside_width Get the width consumed by padding, margin and borders. finalize Method provided to give component one last opportunity to put it's contents into the provided space. Called after prepare. padding Set this component's padding, which should be an instance of Insets. Padding is the space inside the component's bounding box, as in CSS. This padding should be between the border and the component's content. page If true then this component represents stand-alone page. This informs the driver that this component (and any children) are to be renderered on a single surface. This only really makes sense in formats that have pages such as PDF of PostScript. prepare Method to prepare this component for drawing. This is an empty sub and is meant to be overridden by a specific implementation. preferred_height Set/Get this component's preferred height. Used to inform a layout manager. preferred_width Set/Get this component's preferred width. Used to inform a layout manager. to_string Get a string representation of this component in the form of: $name $x,$y ($widthx$height) visible Set/Get this component's visible flag. width Set/Get this component's width. AUTHOR
Cory Watson, "<gphat@cpan.org>" BUGS
Please report any bugs or feature requests to "bug-geometry-primitive at rt.cpan.org", or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Geometry-Primitive <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Geometry-Primitive>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. COPYRIGHT &; LICENSE Copyright 2008-2009 by Cory G Watson. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.3 2011-06-02 Graphics::Primitive::Component(3pm)
All times are GMT -4. The time now is 02:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy