Posts

Showing posts from December, 2011

Evaluating A Postfix Expression Using Stack DataStructures

#include"stdafx.h" #include<math.h> #include<iostream> # define MAX_STACK 150  using namespace std; class stacks {    int value,item,top;    int stack[MAX_STACK];    public:       stacks()       {   top=(-1);       }       void push(float);       float pop(); }; void stacks::push(float value) {    if(top==MAX_STACK)    {       cout<<"Stack is full!\nOverflow!";          exit(0);    }    else    top++;    stack[top]=value; } float stacks::pop() {    if(top<0)    {       cout<<"Stack is empty!\nUnderflow!";       exit(0);    }    else    item=stack[top];    top--;    return(item); } int main() {        stacks stk1;    char expression[150],oper_string[8],ch;    oper_string[0]='\0';    float value,operand1,operand2,val;    int pos=0,p=0;    cout<<"Enter a postfix expression: ";    gets(expression);    while(expression[pos]!='\0')    {       ch=exp
Using DateTime Object: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 {     class Program     {         static void Main( string [] args)         {             //1             //To get current Date And Time             DateTime DT = new DateTime ();             DT = DateTime .Now;             Console .WriteLine( "Current date is {0} " , DT.Date);             //2             //Initalize datetime object using overloads             DateTime DT = new DateTime (2008, 7, 4, 21, 35, 15, 777);             Console .WriteLine( "Current date is {0} " , DT);             //3             //Extracting Parts from datetime object.             DateTime DT = new DateTime ();             DT= DateTime .Now;             Console .WriteLine( "Day of week is {0} ,day name is {1} ,year is {2} " ,   DT.Day,DT.DayOfWeek, DT.Year);             //4             //To add days,months,years,hours,minutes,se

Tree Data Structure

// Mairaj.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; class node {           private :           int val;           node *right;           node *left; public :           void setvalue( int x)           {                    val=x;           }           int getvalue()           {                    return val;           }           void setright(node *a)           {                    right=a;           }           node * getright()           {                    return right;           }     void setleft( node * b)           {                    left=b;           }           node * getleft()           {                    return left;           }           }; class Tree { private :           node *root; public :           Tree( int y)           {                    node *temp= new node();                    root=temp;                    temp->setvalue(y);