1 / 4

STACK (Linear Stack ) Deletion

STACK (Linear Stack ) Deletion. A[4]. Delete an element. A[3]. It means , print the element Available at the top. A[2]. Then decrease the value of top by 1. A[1]. A[0]. Stack is empty so we cannot delete an element. top= -1. STACK (Linear Stack ) Deletion.

betrys
Télécharger la présentation

STACK (Linear Stack ) Deletion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. STACK (Linear Stack) Deletion A[4] Deletean element A[3] It means , print the element Available at the top A[2] Then decrease the value of top by 1 A[1] A[0] Stack is empty so we cannot delete an element top= -1

  2. STACK (Linear Stack) Deletion Suppose 3 elements are available A[4] So , value of top is 2 A[3] Coding of deletion: 30 top= 2 A[2] cout<<A[TOP]; 20 A[1] top= 1 TOP--; 10 top= 0 A[0] Delete one more element top= -1 cout<<A[TOP]; TOP--; Delete one more element Now, we cannot delete an element Stack is empty Delete one more element cout<<A[TOP]; TOP--; Value of top =-1

  3. Coding of Deleting an element in stack Delete Operation is called as :Pop() Important Point: Before Deleting an element , we have to check whether the stack is emptyor not Stack is empty: if top = -1 If Stack is not empty, Cout<<A[top]; Top---;

  4. Coding of push() void pop() { if(top==-1) cout<<“Underflow or empty”; else { cout<<“Deleted element is:”<<a[top]; top---; } }

More Related