Skip to main content

Posts

Any expression can be represented using three types of expressions (Infix, Postfix and Prefix). We can also convert one type of expression to another type of expression like Infix to Postfix, Infix to Prefix, Postfix to Prefix and vice versa. To convert any Infix expression into Postfix or Prefix expression we can use the following procedure… Find all the operators in the given Infix Expression. Find the order of operators evaluated according to their Operator precedence. Convert each operator into required type of expression (Postfix or Prefix) in the same order. To convert Infix Expression into Postfix Expression using a stack data structure, We can use the following steps... Read all the symbols one by one from left to right in the given Infix Expression. If the reading symbol is operand, then directly print it to the result (Output). If the reading symbol is left parenthesis '(', then Push it on to the Stack. If the reading symbol is right parenthesis ')', then Pop all the contents of stack until respective left parenthesis is poped and print each poped symbol to the result. If the reading symbol is operator (+ , - , * , / etc.,), then Push it on to the Stack. However, first pop the operators which are already on the stack that have higher or equal precedence than current operator and print them to the result.

 #include<stdio.h> #include<stdlib.h> void evaluate(); void push(char); char pop(); int prec(char); char infix[30], postfix[30], stack[30]; int top = -1; void main() {             printf("\nEnter the valid infix expression:\t");             scanf("%s", infix);             evaluate();             printf("\nThe entered infix expression is :\n %s \n", infix);             printf("\nThe corresponding postfix expression is :\n %s \n", postfix); } void evaluate() {             int i = 0, j = 0;             char symb, temp;             push('#');             for(i=0; infix[i] != '\0'; i++)             {                       ...
Recent posts

Shyam has a lot of books messed on the floor. Therefore, he wants to pile up the books that still have some remaining exercises into a single pile. He will grab the books oneby-one and add the books that still have remaining exercises to the top of the pile. Whenever he wants to do a book exercise, he will pick the book with the minimum number of remaining exercises from the pile. In order to pick the book, he has to remove all the books above it. Therefore, if there are more than one books with the minimum number of remaining exercises, he will take the one which requires the least number of books to remove. The removed books are returned to the messy floor. After he picks the book, he will do all the remaining exercises and trash the book. Since number of books is rather large, he needs your help to tell him the number of books he must remove, for picking the book with the minimum number of exercises. Whenever he wants to do a book exercise, there is at least one book in the pile. Implement a program for this scenario

 #include<iostream> using namespace std; class Books { public:  string subName[50]; int subEx[50], num; void readData() { int i; cout << "Enter number of books: "; cin >> num; for(i=0; i<num; i++) { cout << "Enter book name: "; cin >> subName[i]; cout <<"Enter number of exercises in " << subName[i] << ": "; cin >> subEx[i]; } } void sortStack() { string tempName; int i, j, tempEx; for(i=0; i<num-1; i++) { for (j=0; j<num-i-1; j++) { if(subEx[j] > subEx[j+1]) { tempEx = subEx[j]; subEx[j] = subEx[j+1]; subEx[j+1] = tempEx; tempName = subName[j]; subName[j] = subName[j+1]; subName[j+1] = tempName; } } } } void displayStack() { int j; for(j=0;j<num;j++) cout<<"\nRemaining exercies in "...

10 Amzing Windows Commands You Should Know

10 Amazing Windows Commands You Should Know There are some things you can only do from the command line—even in Windows. Some of these tools don’t have graphical equivalents, while others are just plain faster to use than their graphical interfaces. If you’re into using PowerShell over Command Prompt, you should note that all the commands we’re covering in this article work just the same in either tool. And obviously, we can’t possibly cover all the useful commands that these tools offer. Instead, we’ll be focusing on commands that should be useful even if you’re not a command-line person. RELATED:   10 Ways to Open the Command Prompt in Windows 10 ipconfig: Quickly Find Your IP Address RELATED:   10 Useful Options You Can Configure In Your Router's Web Interface You can find your IP address from the Control Panel, but it takes a few clicks to get there. The  ipconfig  command is a fast way of determining your computer’s IP address and other ...

How to Create the Ultimate USB Key Ring to Solve Any Computer Problem

How to Create the Ultimate USB Key Ring to Solve Any Computer Problem If you’re “the computer guy” (or girl) to your friends and family, you’re probably asked to diagnose and fix their problems on a regular basis. If you can’t stand to tell them to leave you alone, you might as well embrace your role and come prepared with one key ring full of flash drives to rule them all. With a set of drives filled with portable versions of useful PC repair and maintenance programs, along with some bootable troubleshooting utilities, you’ll be ready for just about any problem. Step One: Grab Your Drive(s) Any USB drive should work for this guide. You can fit most of the portable apps below on one single flash drive, though a few of the tools require a dedicated drive that you can boot from—this allows you to solve problems on computers that won’t even turn on. The best approach is probably to have a big, fast primary drive with most of the self-contained programs (and which you ...

The Foobar challenge: Google’s hidden test for developers

The Foobar challenge: Google’s hidden test for developers by Daniel Simmons & Smit Patel You’re just sitting at your desk, minding your own business, trying to get some work done. Then, as inevitably happens, you hit a minor roadblock: your code throws a cryptic error message. “No problem” you think. This isn’t your first rodeo. So you copy and paste the error message verbatim into Google and see what you get. No luck. There are plenty of search results, but none of them fit your situation closely enough to really provide a useful answer. And so begins the creative Googling process. You try several combinations of the error + the context that you’re using it in. You try including the name of the library that you’re using. You know you’re getting closer… Now on your sixth attempt, you try another combination of search terms and hit return. The page loads and you’ve just begun skimming over the results when, suddenly, your browser window splits open and y...

Design, Develop and Implement a menu driven Program in C for the following Array operations a. Creating an Array of N Integer Elements b. Display of Array Elements with Suitable Headings c. Inserting an Element (ELEM) at a given valid Position (POS) d. Deleting an Element at a given valid Position(POS) e. Exit. Support the program with functions for each of the above operations.

CODE IN Cpp Language  :- /** * * * @Author :- SMITPATEL */ #include"cstdlib" #include"iostream" #include"stack" using namespace std; const int MAX = 100;       int tp = -1;       int M[MAX]; void push(int item); int pop(); void palindrome(); void show();//display function void push(int item) {   if( tp == MAX - 1)   {     cout << "**__**__**__Stack Overflow__**__**__**" << endl;     return ;   }   tp = tp + 1;   M[tp] = item; } int pop() {   int item;   if( tp == -1)   {     cout << "**__**__**__Stack Underflow__**__**__**" << endl;     return -1;   }   item = M[tp];   tp = tp-1;   return item; } void show() {   int i;   if(tp == -1)   {     cout << "**__**__**__There is no Stack__**__**__**" << endl << endl;//Stack is empty.     return;   }   cout << endl ...

Total Pageviews