हिंदी माध्यम नोट्स
Stack : Implementation Using Array in c language in hindi , स्टैक को अरे का यूज़ करते हुए इम्प्लीमेंट करना
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
Recent Posts
Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic
Question Tag Definition • A question tag is a small question at the end of a…
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
Report Writing examples in english grammer How to Write Reports explain Exercise
Report Writing • How to Write Reports • Just as no definite rules can be laid down…
Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th
Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…