guys im using reverse polish notation in link list my problem is every time i enter the OPERATOR (+) it will add and that operator display as '0' im having trouble in that operator i need to display it as blank >_< help me guys
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define p printf
#define s scanf
#include<conio.h>
#include<windows.h>
int number;
char choice;
char operators;
char str[20];
struct node
{
int data;
struct node *link;
};typedef struct node *nodepointer;
void insertfront(nodepointer &head,int number)
{
nodepointer newnode;
newnode=(nodepointer)malloc(sizeof(struct node));
newnode->data=number;
newnode->link=head;
head=newnode;
}
void deletefront(nodepointer &head)
{
nodepointer temp;
if(head==NULL)
{
p("\nNothing to delete");
}
else if(head!=NULL)
{
temp=head;
head=temp->link;
free(temp);
}
}
void display(nodepointer top)
{
int index=1;
if(top==NULL)
{
p("\nNothing to display");
}
else if(top!=NULL)
{
while(top->link!=NULL)
{
if(strcmp(str,"+")==0)
{
}
p("%i\n",top->data);
top=top->link;
}
if(strcmp(str,"+")==0)
{
}
p("%i",top->data);
}
}
void pop_add(nodepointer top)
{
nodepointer after;
nodepointer before;
if(top==NULL || top->link==NULL)
{
p("List is empty or must have two operands first before inserting operator...");
getch();
}
else
{
before=NULL;
after=top;
while(after->link!=NULL)
{
before=after;
after=after->link;
}
p("\n\n\Before is %i",before->data);
before->data=before->data+after->data;
before->link=NULL;
p("\n\n\After is %i",after->data);
}
}
main()
{
nodepointer top;
top=NULL;
do
{
system("cls");
display(top);
p("\n[1]Push");
p("\nKey choice: ");
fflush(stdin);
s("%c",&choice);
switch(choice)
{
case '1':
p("\nEnter number: ");
fflush(stdin);
gets(str);
number=atoi(str);
if(strcmpi(str,"+")==0)
{
pop_add(top);
}
insertfront(top,number);
break;
}
}while(1==1);
system("pause");
}