Preview

Conversion from Infix to Postfix in C

Good Essays
Open Document
Open Document
279 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Conversion from Infix to Postfix in C
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
#include<ctype.h>
#define max 30

struct stack
{
char opstack[max]; int tos;
};

void push(struct stack *,char); char pop(struct stack *); int prece(char );

void main()
{
int i,j=0,k,l; char ch,infix[max], postfix[max]; stack pq; pq.tos=-1; A: clrscr(); printf("\nEnter the infix string:\t"); gets(infix); for(i=0;infix[i]!='\0';i++)
{
if (infix[i]=='(') push(&pq,infix[i]); else if (isalpha(infix[i])) { postfix[j]=infix[i]; j++; } else if (infix[i]=='+'||infix[i]=='-'||infix[i]=='/'||infix[i]=='$'||infix[i]=='*') { if(pq.tos!=-1 && prece(pq.opstack[pq.tos])>=prece(infix[i])) {ch=pop(&pq); postfix[j]=ch; j++; } push(&pq,infix[i]); } else if (infix[i]==')') { for(;pq.opstack[pq.tos]=='(';) l=pq.tos; for(k=-1;k<l;k++) { postfix[j]=pop(&pq); j++; } } else { printf("\nError: Your infix contains invalid characters. Press any key to try again.\t"); getch(); goto A; }
}
while (pq.opstack[pq.tos]!=NULL) { postfix[j]=pop(&pq); j++; } postfix[j]='\0'; for(i=0;i<j;i++)
{
if(postfix[i]!='(') printf("%c",postfix[i]); } getch(); }

int prece(char a)
{
int q; switch (a) { case '$': q=4; break;

case '*': case '/': q=3; break;

case '+': case '-': q=2; break;

case '(': q=1; } return(q); }

void push(struct stack *ps,char b)
{
ps->tos++; ps->opstack[ps->tos]=b;
}

char pop(struct stack *ps)
{
char p; p=ps->opstack[ps->tos]; ps->tos--; return(p);

You May Also Find These Documents Helpful

  • Satisfactory Essays

    cout << "You are in factorial program of C++. Please enter a +ve integer:- ";…

    • 426 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    INF220 WEEK 1 ASSIGNMENT

    • 678 Words
    • 2 Pages

    There are many shipping companies present in today’s society. One of the leaders in this industry is UPS. In order to compete with other large shipping companies, UPS has had to adapt with the ever changing industry. Since the beginning of the company in 1907, UPS has grown to one of the top leaders for domestic and international shipping. In this short paper I will discuss the growth of this leading company, along with the difficulties this company faces on a daily basis.…

    • 678 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    printf(" %d \t\t %d\n\n",stfor->wt,stfor->tt); ttl_wt += stfor->wt; ttl_tt += stfor->tt; temp = np = stfor; del_node(np,1) ; ++i; } else { stfor->bt -= qt; stfor->tt = temp->tt + qt; printf(" %d \t\t %d\n\n",stfor->wt,stfor->tt); np = temp = stfor; del_node(np,2); ins_node(temp); } }while(stfor !=…

    • 401 Words
    • 2 Pages
    Better Essays
  • Satisfactory Essays

    Infant-­‐Toddler Observation Project ~ Example of anecdotal observation and analysis Anecdotal Observation # 1 09/30/11 at 11:00 am Infant Observation Room – Cabrillo College Brief description of environment: OBSERVADOR: John Q. Student Child’s name: Gina Age: 14 months DOB July 2010 In the infant classroom yard there are five other infants and two adult caregivers. There’s a large blanket with various infant toys.…

    • 460 Words
    • 17 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Assignment 4 INTB 3330

    • 433 Words
    • 2 Pages

    1. Discuss Hall's High and low context framework and suggest how it might be useful in an international business situation.…

    • 433 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Linux Assignment 3

    • 1307 Words
    • 6 Pages

    1. What does the shell ordinarily do while a command is executing? What should you do if you do not want for a command to finish before running another command?…

    • 1307 Words
    • 6 Pages
    Satisfactory Essays
  • Satisfactory Essays

    In this Assignment you will need to complete an analysis chart for ten (10) medical terms. Please be sure to complete the information for all 14 spaces. If there is not an applicable answer please indicate this by entering “n/a” in the space. At the end of the project be sure to list all applicable references and cite them in APA format.…

    • 687 Words
    • 9 Pages
    Satisfactory Essays
  • Good Essays

    Unix File

    • 566 Words
    • 3 Pages

    In order to understand how to control access to a file in a system that supports 5,000 users to 4,990 of those users, a basic understanding of the file permissions of a file on a UNIX system is necessary. A user has the ability to perform three basic actions to a file, read, write and execute. These three actions will be represented by r, w, and x respectively. A UNIX system uses a combination of these characters to control the file permissions. The first three characters represent the owner’s permissions, the middle three characters represent the group’s permissions, and the last three characters represent others permission. A sample of file permission would look like the following:…

    • 566 Words
    • 3 Pages
    Good Essays
  • Better Essays

    The Declaration and Address’ intended audience was all who love our Lord Jesus Christ. The intended audience ties in with the message of most of the document in that it speaks of unity. A major part of the Stone-Campbell Movement was to bring unity and the Stone-Campbell Movement was formed through unity. I think a couple of the main reasons why unity is so important in the document was one, because God calls us to unity through Him, and two, because the Stone-Campbell Movement was created through unity. If Stone and Campbell stayed separate in their thoughts, beliefs, and motives the impact they were able to have would not have happened. The importance of unity is far beyond describing. When there is not unity in the Church, then the Church will fall. Division makes anything weak. That is why the topic of unity is discussed with such importance.…

    • 861 Words
    • 4 Pages
    Better Essays
  • Satisfactory Essays

    5) When an input file is opened, its read position is initially set to the first item in the file.…

    • 544 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Postcards is a poem, the last of the immigrant chronicles, written by Peter Skrzynecki. The immigrant Chronicles is a series of poems talking about Skrzynecki’s personal life and experiences of having parents who has emigrated from country under communist influence. This poem specifically talks about a postcard with an image of Warsaw, the largest town in Poland, printed on the front. It is an emotional poem which trigger different types of reactions at different stages of the poem.…

    • 525 Words
    • 3 Pages
    Good Essays
  • Good Essays

    As standard mail becomes obsolete and the electronic revolution takes over, the United States Postal Service needs to develop a new strategic action plan in order to adapt and sustain profitability in this dynamic environment. There are a number or short and long term problems that need to be addressed.…

    • 1063 Words
    • 5 Pages
    Good Essays
  • Good Essays

    LIFO arguments

    • 941 Words
    • 3 Pages

    LIFO accounting is a “timing issue”, rather than a tax gimmick. LIFO accounting reverses itself when demand drops. When companies reach lower-cost inventory layers last year as demand solwed, and at that point, profits rose under LIFO accounting and the company had to pay more in taxes. The same is true when deflation sets in. As the price of replacement inventory drops, taxable income increases, and so does a company’s tax obligation.…

    • 941 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Python - Menu Program

    • 1437 Words
    • 6 Pages

    #Marius Mazuolis #14-12-2012 #assignment Menu Program #------------------------------------- #open file and read data assining it to 2 dimension list def openFile(fileName): bufferFile = open(fileName) bufferTxt = bufferFile.read() bufferFile.close() bufferLines = bufferTxt.split("\n") bufferTable = [] ln=0 for line in bufferLines: if len(line) > 0: if ln != 0: dataLine = line.split(",") dataLine[0] = dataLine[0].capitalize() bufferTable = bufferTable + [dataLine] else: dataLine = line.split(",") for dt in dataLine: i = dataLine.index(dt) dataLine[i] = dt.upper() bufferTable = bufferTable + [dataLine] ln+=1 return bufferTable #------------------------------------- #------------------------------------- #function to check if number less than 10 to add 0 in front #(send 9 receive 09)…

    • 1437 Words
    • 6 Pages
    Satisfactory Essays
  • Good Essays

    String and T/f

    • 2717 Words
    • 28 Pages

    10. Assume that x, y, and temp are Integer variables. Which of the following lines of code swaps…

    • 2717 Words
    • 28 Pages
    Good Essays

Related Topics