🔒 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
  • 261
    Views
  • 4
    Participants
Last reply from:
Biscoff Frappe

Trending Topics

Online now

Members online
1,005
Guests online
740
Total visitors
1,745

Forum statistics

Threads
2,275,600
Posts
28,964,376
Members
1,231,881
Latest member
kakakoko
Back
Top