Pages

Friday, July 4, 2025

Pop() in Linked List in C++

 int pop() {

if(isEmpty(top)) 

cout << "Stack underflow << endl;

return -1;

}

else 

{

Node* n = top;

int x = n->data;

top=top->next;

free(n);

return x;

     }
}




No comments:

Post a Comment

remove duplicates from sorted array - two pointer approach (leetcode)

  class Solution {     public int removeDuplicates ( int [] nums ) {         // base case: return if array have no el.         if ( nums...