स्टैक ऑपरेशन- स्टैक ऑपरेशन का उपयोग स्टैक को इनिशलायजिंग और डीइनिशलायजिंग करने के लिए किया जाता है। इसके अलावा एक स्टैक निम्नलिखित दो प्राथमिक कार्यों के लिए प्रयोग किया जाता है
Push () – एक तत्त्व स्टैक में जोड़ना
Pop () – एक तत्त्व स्टैक से हटाना
पुश ऑपरेशन (Push Operation) – स्टैक में एक नया डेटा तत्त्व जोड़ने या डालने की प्रक्रिया को पुश ऑपरेशन कहते है। पुश ऑपरेशन निम्नलिखित स्टेप्स की एक श्रृंखला है।
Step 1 – Checks if the stack is full.
Step 2 – If the stack is full, produces an error and exit.
Step 3 – If the stack is not full, increments top to point next empty space.
Step 4 – Adds data element to the stack location, where top is pointing.
Stack Step 5 – Returns success.
यदि स्टैक का लिंक लिस्ट से इम्पलीमेंट करते है तो स्टेप 3 में डायनामिक मैमोरी आवंटित करनी होगी।
पॉप ऑपरेशन (Pop Operation) : स्टैक से एक डेटा तत्त्व को हटाने की प्रक्रिया को पॉप ऑपरेशन कहते है। जब पॉप ऑपरेशन को एक ऐरे की मदद से इम्पलीमेंट करते है तो वास्तव में डाटा तत्त्व को हटाने की बजाए टॉप वेरिएबल को एक से घटते है जबकि लिंक लिस्ट से इम्पलीमेंट करने पर वास्तव में डाटा तत्त्व को हटा कर मैमोरी को deallocates किया जाता है। पॉप ऑपरेशन निम्नलिखित स्टेप्स की एक श्रृंखला है
Step 1 – Checks if the stack is empty.
Step 2 – If the stack is empty, produces an error and exit.
Step 3 – If the stack is not empty, accesses the data element at which top is pointing.
Step 4 – Decreases the value of top by 1.
Step 5 – Returns success.