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

3Sum - Leetcode solution - How i turned into two-pointer approach?

  class Solution {     public List < List < Integer >> threeSum ( int [] nums ) {         Arrays . sort (nums); // first sort...