Top Banner
WELCOME
24

Project of data structure

Apr 12, 2017

Download

Engineering

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Project of data structure

WELCOME

Page 2: Project of data structure

TOPIC

STACK

Page 3: Project of data structure

CONTENTSIntroduction

Application

Conclusion

Page 4: Project of data structure

PRESENTED BY

Khadijatul Kobra ShilaI.D:142-15-3616

Page 5: Project of data structure

INTRODUCTION A stack is a data structure that stores

data in such a way that the last piece of data stored, is the first one retrieved.

LAST IN FIRST OUT = LIFO

To get the bottom plate out, you must first remove all the plates above.

Example of stack

Page 6: Project of data structure

All these applications follow the LIFO logic.

REAL LIFE: Stacks are present everyday life.From

the books in a library, to the blank sheets of paper in a printer tray systems are used STACK to complete their acts.

#PILES OF BOOKS:A book is added on top of a pileof books, while removing a bookfrom a pile also takes the book ontop of a pile in everywhere.

APPLICATIONS:1

Page 7: Project of data structure

APPLICATIONS:1#VISULAZE STAGE:

PUSH

POP

TOP

Pile of Books

Page 8: Project of data structure

APPLICATIONS:1#SOURCE CODE:

void push(int *top, element item){ /* add an item to the global stack */ if (*top >= MAX_STACK_SIZE-1) { stack_full( ); return; } stack[++*top] = item;}

Push element pop(int *top)

{ /* return the top element from the stack */ if (*top == -1) return

stack_empty( ); /* returns and error key */ return stack[(*top)--]; }

Pop

Page 9: Project of data structure

PRESENTED BY

Rahul DebnathID: 142-15-3484

Page 10: Project of data structure

APPLICATIONS:2RLATED TO COMPUTER SCIENCE: Below are a few applications of stacks in computing.#REVERSING STRING: A simple application of stack is reversing strings.

To reverse a string , the characters of string are pushed onto the stack one by one as the string is read from left to right. To reverse the string ‘REVERSE’ the string is read from left to right and its characters are

pushed.LIKE:

Page 11: Project of data structure

APPLICATIONS:2ESREVE

R

REVERSE

ESREVER

PUS

HPOP

String is

Reverse String

Stack

#VISULAZE STAGE:

Page 12: Project of data structure

APPLICATIONS:2#define MAX 20int top = -1;

char stack[MAX];char pop();void push(char);

main(){char str[20];int i;printf(“Enter the string : ” );gets(str);

for(i=0;i<strlen(str);i++)push(str[i]);

for(i=0;i<strlen(str);i++) str[i]=pop(); printf(“Reversed string is : “);puts(str);

void push(char item){ if(top == (MAX-1)) { printf(“Stack Overflow\n”); return; } stack[++top] =item; }/*End of push()*/

char pop(){if(top == -1){printf(“Stack Underflow\n”);exit(1);}

return stack[top–];}

Page 13: Project of data structure

PRESENTED BY

Abu Zafor Tomal I.D:142-15-3816

Page 14: Project of data structure

#Calculator Methodology:Every arithmetic operation in

calculator followthe stack postfix notation.

APPLICATIONS:3

* +

9 6 39+6*3

EquationPostfix string

Stack

Page 15: Project of data structure

APPLICATIONS:3 Create Stack While(not end of postfix notation){

ch = getch()if(ch is operand)

push(ch)else{

operand1 = pop()operand2 = pop()result = operand2 ch

operand1push(result)}

}Result = pop()

Page 16: Project of data structure

PRESENTED BY

Abul Hasnath LimonID:142-15-3532

Page 17: Project of data structure

APPLICATIONS:4 #Function ( recursive ): A very good example of stack is Function.

Summation of positive integer can be implemented by

recursive function and the functions are stored in a stack to

maintain the sequence of summation.

When a function is called within a function then the previous

function is stored in a stack with it’s local variables.

Summation of positive numbers with code example:

Page 18: Project of data structure

APPLICATIONS:4 #include <stdio.h>

int sum(int n); int main(){

int num,add; printf("Enter a positive integer:\n"); scanf("%d",&num); add=sum(num); printf("sum=%d",add);

} int sum(int n){

if(n==0) return n;

else return n+sum(n-1); /*self call to function

sum() */ }

Enter a positive integer: 5 15

Output

Page 19: Project of data structure

APPLICATIONS:4 For better visualization of

recursion inthis example:sum(5) =5+sum(4) =5+4+sum(3) =5+4+3+sum(2) =5+4+3+2+sum(1) =5+4+3+2+1+sum(0) =5+4+3+2+1+0 =5+4+3+2+1 =5+4+3+3 =5+4+6 =5+10 =15

Sum(1)Sum(2)Sum(3)Sum(4)Sum(5)

All functions are pushed in stack

Page 20: Project of data structure

PRESENTED BY

Umme HabibaID:142-15-3677

Page 21: Project of data structure

Implementation : Palindrome

A palindrome is a word, phrase, number, or other sequence of

Characters which reads the same backward or forward.

Allowances may be made for adjustments to capital letters,

punctuation, and word dividers.

Suppose :ABCDCBA is a palindromeFGHHGF is a palindromeASDFASDF is not a palindrome

APPLICATIONS:5

Page 22: Project of data structure

APPLICATIONS:5

CIVIC

CIVIC

PUSH

POP

Stack Stack

Palindrome Word

After pushing and popping, CIVIC word remain unchanged

#VISULAZE STAGE:

Page 23: Project of data structure

Source code:

char stk[50];int top=-1;void push(char c){top++;stk[top]=c;}char pop(){char c;c=stk[top];top–;return c;}void main(){char in[30],b[30];int i;

printf(“\n\n ENTER UR STRING\t”);gets(in);

APPLICATIONS:5 for(i=0;in[i]!=‘’;i++){

push(in[i]);}i=0;while(top!=-1){

b[i]=pop();i++;

}b[i]=‘’;if(strcmp(in,b)==0){

printf (“\n STRING isPALLINDROME”);

}else{

printf (“\n STRING IS NOT PALLNDROME”);}

}

Page 24: Project of data structure

THE END

Thank You