JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

Stack : Implementation Using Array in c language in hindi , स्टैक को अरे का यूज़ करते हुए इम्प्लीमेंट करना

स्टैक को अरे का यूज़ करते हुए इम्प्लीमेंट करना , Stack : Implementation Using Array in c language in hindi :-
Stack  को दो प्रकार से  Implementation कर सकते है (i) using array (ii) using linked list |linked लिस्ट की तुलना मे array मे push (insertion ) और pop (delete) operation को करना easy होता है |लेकिन array के साथ dynamic memory एलोकेशन possible नहीं है |
push operation :
push operation की  algorithm है :-
1. stack की emptyness को check किया जाता है |
2.अगर stack array full है तब error message print हो जायेगा और प्रोप्ग्राम से exit हो जायेगा
3.अगर stack full नहीं है तब stack array के top element को top+1 से increment करना |
और नए element को add करना |Pop operation
pop operation की algorithm है :-
1.stack की emptiness को check करना है |
2.अगर stack empty है तब error of under full का message आ जायेगा |
3.अगर stack empty नहीं है तब delete element print हो जायेगा और top ,top-1 से decrement हो जायेगा |Source Code
#include<stdio.h>
#include<conio.h>
int s[100],ch, num ,top_stack,new,i;
void push( );
void pop( );
void display_stack ();
void main()
{
clrscr();
top_stack=-1;
printf(“\n Enter the stack size :”);
scanf(“%d”,&num);
printf(“\n Operation list “);
printf(“\n\t Enter ‘1’ for push operation “);
printf(“\n\t Enter ‘2’ for pop operation “);
printf(“\n\t Enter ‘3’ for display operation “);
printf(“\n\t Enter ‘4’ for exit “);
do
{
printf(“\n Enter Your choice :”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
{
push();
break;
}
case 2:
{
pop();
break;
}
case 3:
{
display_stack ();
break;
}
case 4:
{
printf(” Enewit operation perform “);
break;
}
default:
{
printf (“\n\t Please Enter a Valid choice among ‘1’,’2′,’3′,’4′.”);
}

}
}
while(ch!=4);
getch();
}
void push()
{
if(top_stack>=num-1)
{
peintf(“Stack is full”);

}
else
{
printf(” Enter a value that you want to insert :”);
scanf(“%d”,&new);
top_stack++;
s[top_stack]=new;
}
}
void pop()
{
if(top_stack<=-1)
{
printf(“Stack is mot over full “);
}
else
{
printf(“\n\t The delete element is %d”,s[top_stack]);
top_stack–;
}
}
void display_stack ()
{
if(top_stack>=0)
{
printf(“\n Stack Elements \n”);
for(i=top_stack; i>=0; i–)
printf(“\n%d”,s[i]);
}
else
{
printf(“\n Empty Stack “);
}

}

इस पप्रोग्राम मे , char function है :
1.main() : इस function मे , प्रोग्राम की main body होती है |जिसमे सभी function push() ,pop() और display_stack () को call किया जाता है |
2.push() : इस function का use ,stack array मे element को add करने के लिए किया जाता है |
3.pop() : इस function का use , stack element मे element को डिलीट करने के लिए किया जाता है |
4.display_stack() : इस function का use ,stack के सभी element को display करने के लिए किया जाता है |

सबसे पहले ,header portion मे कुछ global variables s[100],ch, num ,top_stack,new,i को declare किया गया है |जैसे
s[100]: ये stack array है जो की stack data struture की तरह कार्य करेगा |
ch : इस variable मे यूजर द्वारा दिए गये choice को assign किया जायेगा |
num : इस variable मे ,यूजर द्वारा दिए गये stack elements की सख्या या size को assign किया जायेगा |
top_stack : ये array के first element के address को hold करता है |
new : इस variable मे , यूजर द्वारा दिए गये नए element को assign किया गया है |

main() मे ,
इस function मे ,
1.यूजर से stack की size को input किया जाता है |जिसे num मे assign किया जाता है |
2.उसके बाद यूजर से choice के लिए input लिया जाता है जिससे कोनसा function perform होगा \ये देसिद होता है |जैसे
‘1’ से push operation होगा |
‘2’ से pop operation होगा |
‘3’ से display operation होगा |
‘4’ से exit operation होगा |
यूजर द्वारा दिए गये input के आधार पर हो function को call किया जाता है |

push operation :
1.सबसे पहले condition check होती है |इस condition से stack की emptyness को check किया जाता है |जैसे 2.यूजर द्वारा input size 6 तब (top>size-1) यानि (-1>5) condition check होगी |
अगर ये condition सही होगी stack overfull का meassage आ जाये गा |अन्यथा तो step 3 perform होगी |
3.यूजर से new data को input करते है |
फिर stack के top को increment किया जाता है जिसमे element add होगा |

pop operation
1. सबसे पहले top की value को -1 से check की जाती है |अगर top की value ,-1 है तब stack empty होगा |
2. अगर stack empty नही है तब, top position के element को print करेगे |
3.और top की position को top -1 से set करेगे |
जिससे top position पर स्थित element डिलीट हो जायेगा |

display operation
सबसे top की value को ‘0’ से check किया जाता है |
अगर top की value ‘0’ से ज्यादा होती है तब loop चलाया जाता है |loop की body मे ,
1. stack के top position पर स्थित element को print किया जाता है |
2.फिर top की value को top -1 से set किया है |
ये loop tab तक चलता है जब तक top की value ‘0’ नहीं हो जाती है |
3.अगर top position की value ‘0’ है ,तब empty stack का message print हो जायेगा |

इस प्रोग्रम का  आउटपुट होगा :
Enter the stack size : 5
Operation list
Enter ‘1’ for push operation
Enter ‘2’ for pop operation
Enter ‘3’ for display operation
Enter ‘4’ for exit
Enter Your choice : 1
Enter a value that you want to insert : 12
Enter Your choice : 2
Enter Your choice : 3
Empty Stack

Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

1 month ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

1 month ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now