#include <iostream>
#include <stack>
#include <string>
#include <cctype>
using namespace std;
class infix_to_postfix
{
protected:
string exp;
string infixexp;
stack<char> charstack;
bool prcd(char a, char b)
{
return a > b;
}
public:
infix_to_postfix(string str)
{
exp = str;
}
void push_to_stack()
{
for(int i = 0; exp[i]; ++i)
{
if(exp[i] == ' ')
continue;
if(isalnum(exp[i]))
{
infixexp += exp[i];
}
else
{
while(!charstack.empty() && prcd(exp[i], charstack.top()))
{
infixexp += charstack.top();
charstack.pop();
}
charstack.push(exp[i]);
}
}
while(!charstack.empty())
{
infixexp += charstack.top();
charstack.pop();
}
}
string print()
{
return infixexp;
}
};
class evaluate {
public:
evaluate(string str)
{
exp = str;
}
void peform()
{
int res;
for(int i = 0; i < exp.length(); i++)
{
if(isalnum(exp[i]))
{
nums.push(exp[i] - '0');
}
else
{
if(!nums.empty())
{
int a = nums.top();
nums.pop();
int b = nums.top();
nums.pop();
res = doit(b, exp[i], a);
}
nums.push(res);
}
}
}
int retres()
{
return nums.top();
}
protected:
string exp;
stack<int> nums;
private:
int doit(int a, char c, int b)
{
switch(c)
{
case '+':
return a + b;
break;
case '-':
return a - b;
break;
case '*':
return a * b;
break;
case '/':
return a / b;
break;
}
}
};
int main()
{
string infixstr;
infix_to_postfix itop("5 * 2 + 3 * 1 - 9");
itop.push_to_stack();
infixstr = itop.print();
cout << infixstr << endl;
evaluate ev(infixstr);
ev.peform();
int res = ev.retres();
cout << res << endl;
return 0;
}
Monday, October 20, 2014
Josephus Problem Solvation code in C++
#include<iostream>
using namespace std;
struct node{
int val;
node *next;
};
void insert_node(int);
void print();
void josephus(int);
node *head,*nptr,*tptr;
int main(){
head = NULL;
int start,n;
cout << "Enter node number: " << endl;
cin >> n;
insert_node(n);
cout << "The persons are:" << endl;
print();
cout << "Enter start number: " << endl;
cin >> start;
josephus(start);
return 0;
}
void josephus(int start){
node *ptr,*qptr;
qptr = ptr = head;
for (int i = 1; i < start; i++){
ptr = ptr->next;
qptr = ptr;
}
while (ptr->next != ptr){
qptr->next = ptr->next->next;
ptr = qptr->next;
qptr = ptr;
}
head = ptr;
cout << "The person survived is :" << ptr->val << endl;
}
void insert_node (int n){
for(int i = 0; i < n; i++){
nptr = new node;
nptr->val = i+1;
nptr->next = NULL;
if (head == NULL){
head = nptr;
tptr = nptr;
}
else{
tptr->next = nptr;
tptr = nptr;
}
}
tptr->next = head;
}
void print(){
tptr = head;
cout << tptr->val << "->";
tptr = tptr->next;
while (head != tptr){
cout << tptr->val << "->";
tptr = tptr->next;
}
cout<< endl;
}
using namespace std;
struct node{
int val;
node *next;
};
void insert_node(int);
void print();
void josephus(int);
node *head,*nptr,*tptr;
int main(){
head = NULL;
int start,n;
cout << "Enter node number: " << endl;
cin >> n;
insert_node(n);
cout << "The persons are:" << endl;
print();
cout << "Enter start number: " << endl;
cin >> start;
josephus(start);
return 0;
}
void josephus(int start){
node *ptr,*qptr;
qptr = ptr = head;
for (int i = 1; i < start; i++){
ptr = ptr->next;
qptr = ptr;
}
while (ptr->next != ptr){
qptr->next = ptr->next->next;
ptr = qptr->next;
qptr = ptr;
}
head = ptr;
cout << "The person survived is :" << ptr->val << endl;
}
void insert_node (int n){
for(int i = 0; i < n; i++){
nptr = new node;
nptr->val = i+1;
nptr->next = NULL;
if (head == NULL){
head = nptr;
tptr = nptr;
}
else{
tptr->next = nptr;
tptr = nptr;
}
}
tptr->next = head;
}
void print(){
tptr = head;
cout << tptr->val << "->";
tptr = tptr->next;
while (head != tptr){
cout << tptr->val << "->";
tptr = tptr->next;
}
cout<< endl;
}
Thursday, September 25, 2014
Monday, June 23, 2014
Live streaming Brazil world cup 2014 with low connection and video of goals.
Live streaming Brazil world cup 2014 with low connection and clear . You can also see the most popular video of world cup .Click on the Start Live Streaming button then page down and wait 10 second .
Start Live Streaming....
Start Live Streaming....
Friday, June 20, 2014
Online Youtube Converter (Convert video to mp3)
Online YouTube converter site .You can convert any YouTube video in online with in short time and download it .
1. First of all you have to fine your choice able video song then copy the link .
2. Got this site Video Converter and pest your video link on the space and Press Convert Video.
3. After all download your song in audio format .
Thank You
1. First of all you have to fine your choice able video song then copy the link .
2. Got this site Video Converter and pest your video link on the space and Press Convert Video.
3. After all download your song in audio format .
Thank You
Thursday, April 10, 2014
barcelona-vs-atletico-madrid-quarter. hd-live-streaming
http://live-fifa2014.blogspot.com/2014/04/sky-sports-2-hd-live-streaming.html
Go to the link and select stream 4 .....
Saturday, March 22, 2014
International Channels live streaming with low internet speed
Subscribe to:
Posts (Atom)

