Example of structure, C/C++ Programming

Assignment Help:

Example of structure:

struct item

{

                int element;

                node_ptr next;

};

typedef node_ptr stack;

stack create(void)

{

                stack s;

                s=(stack)malloc(sizeof(struct item));

                s->next=NULL;

                return s;

}

void push(stack s,int a)

{

                node_ptr temp;

                temp=(node_ptr)malloc(sizeof(struct item));

                temp->element=a;

                temp->next=s->next;

                s->next=temp;

}

int is_empty(stack s)

{

                return(s->next==NULL);

}

void  pop(stack s)

{

                node_ptr temp;

                temp=s->next;

                s->next=temp->next;

                free(temp);

 

}

int top(stack s)

{

                return(s->next->element);

}

void main()

{

                stack s;

                char exp[100];

                int i;

                s=create();

                clrscr();

                printf("Enter an expression\n");

                scanf("%s",exp);

                for(i=0;exp[i];i++)

                {

                                if(exp[i]=='('||exp[i]=='['||exp[i]=='{')

                                                push(s,exp[i]);

                                else

                                if(exp[i]==')')

                                                if(top(s)!='(')

                                                {

                                                                printf("Invalid Expression");

                                                                return;

                                                }

                                                else

                                                                pop(s);

                                else

                                if(exp[i]=='}')

                                                if(top(s)!='{')

                                                 {

                                                                printf("Invalid Expression");

                                                                return;

                                                 }

                                                else

                                                                pop(s);

                                else

                                if(exp[i]==']')

                                                if(top(s)!='[')

                                                {

                                                                                printf("Invalid Expression");

                                                                return;

                                                }

                                                else

                                                                pop(s);

                }

                if(!is_empty(s))

                                                {

                                                printf("Invalid Expression");

 

                                }

}

 

 


Related Discussions:- Example of structure

Write a program to change the matrix program, Change the matrix program (pr...

Change the matrix program (program 3) slightly. Overload == operator to compare two matrices to be added or subtracted. i.e., whether the column of first and the row of second

Linear iterative process, (a) Write a recursive procedure (digits n) that c...

(a) Write a recursive procedure (digits n) that computes the number of digits in the integer n using a linear recursive process. For example, (digits 42) should return 2 and (digit

Compiler related, Please give me a programming code of first & follow wit...

Please give me a programming code of first & follow with c or c++ laqnguage .When anyone give me the programming code of first & follow please explain every lines with the help

C program for count the no which you want , # include stdio.h> # include...

# include stdio.h> # include string.h> # include conio.h> void main() {           int i=0,j=0,b=0,count=0;           int a[100];           for(i=0;i

College, #question.College life is tough. Eating pizza for every meal is h...

#question.College life is tough. Eating pizza for every meal is hitting you hard. You are looking at working out to stay healthy. You found a web site that tells you how many ca

What are virtual functions in c++, A virtual function permits derived class...

A virtual function permits derived classes to replace the implementation given by the base class. The compiler makes sure the replacement is always known as whenever the object in

What are compound statements, What are compound statements? - Compound ...

What are compound statements? - Compound statements are made up of two or more program statements that are executed together. They may be executed with a loop. - Curly brack

Structure, Write a function that calculates the number of elapsed days betw...

Write a function that calculates the number of elapsed days between two dates. For example the days between Feb 3, 1970 and June 21, 1980? Becareful for the Leap year

Loop, A company needs 200 pencils per year . you cannot simply use this pr...

A company needs 200 pencils per year . you cannot simply use this price as the cost of pencils two years from now. Because of inflation the cost is likely to be higher than it is

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd