Pages

Friday, July 4, 2025

Push() in Linked List in C++

Node* push(Node* top, int x) {

    Node* n = new Node; // Memory allocation 

    

    if (!n) {  // or (n == NULL)

        cout << "Stack overflow" << endl;

        return top;

    }

    

    n->data = x;

    n->next = top;

    top = n;


    return top;

}




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...