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

C help, Need help with C network program

Need help with C network program

Palindrome, A palindrome is a string that reads the same from both the ends...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Luminous Jewels - The Polishing Game, Byteland county is very famous for lu...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Pointers, one of the applications of computers in numerical analysis is com...

one of the applications of computers in numerical analysis is computing the area under a curve. one method of calculating the area under acurve is to divide the area int a number o

Assignment, (RationalNumber Class) A rational number is a number that can b...

(RationalNumber Class) A rational number is a number that can be represented as the quotient of two integers. For example, 1/3, 5/7, 7/2, and so forth are rational numbers (By 2/1

C program for function of compound interest, C Program for FUNCTION  OF CO...

C Program for FUNCTION  OF COMPOUND INTEREST float ci(float,float,float); void main() {           float p=0,r=0,n=0,k=0;           clrscr();           printf("EN

Algorithm and flowcharts, algorithm to find out all the factors of given po...

algorithm to find out all the factors of given positive integers

Padovan stringf, A Padovan string P(n) for a natural number n is defined as...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation.

C program for add, C Program for ADD,SUB,MUL,DIV,REM void main() { ...

C Program for ADD,SUB,MUL,DIV,REM void main() {   int a,b,c,ch=0;           clrscr();           while(ch           { printf(" \n\n 1:- For To Add\n 2:- For

Insertion sort - c program, Insertion sort - C program: Write a progra...

Insertion sort - C program: Write a program in c to define a insertion sort. void main()  {   clrscr();   int a[100],ch,n;   cout   cin>>n;   for (int i=0

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