🔒 Closed C++ LinkedList

Status
Not open for further replies.

Welcome Guest

Established
Hello po, pwede po mag pa help sa Linkedlist, nakuha ko lang po ang code sa ibang websites gusto ko po sana mag pa help paano ko maintindihan ng mabuti ang pag flow ng codes na ito kasi hindi ko siya ma visualize.

C++:
class Node                             
{
   public:
       int data;                         
       Node* next;                       

};

class Stack                           
{
   public:
       Node* top;                       
       Stack()                           
       {
           top = NULL;                 
       }


void push(int data)                   
                      
{
   Node* node = new Node();           
   node -> data = data;                 
   node -> next = top;                 
   top = node;                         
}

void pop()                             
{
   if(top==NULL)                       
   {
       cout << "Stack is empty!" << endl;
   }
   else
   {
       Node* temp = top;     
       top = top -> next;   
                  
       delete temp;         
   }
}

void display()   
{
   if(top==NULL) 
   {
       cout << "Stack is empty!" << endl;
   }
   else
   {
       Node* temp = top; 
       while(temp!=NULL) 
       {
           cout << temp -> data << " ";
           temp = temp -> next;         
       }
       cout << endl;                   
   }
}
};
 
first in first out ang linkedlist diba?

tingin kalang po sa google ng algorithm ng linkedlist, sure ako na meron yan :).
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 272
    Views
  • 4
    Participants
Last reply from:
Biscoff Frappe

Trending Topics

Online now

Members online
526
Guests online
2,008
Total visitors
2,534

Forum statistics

Threads
2,320,220
Posts
29,204,852
Members
1,180,594
Latest member
marc ian o 3002
Back
Top