JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

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

द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन क्या हैं differential equations of second order and special functions in hindi

अध्याय - द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन (Differential Equations of Second Order…

3 hours ago

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

3 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

5 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

1 week ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

1 week 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