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

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...