I've implemented code for the circular linked list but no output is being shown on output window except the following:
Time to print the List
And this is the message my compiler is giving:
-------------- Build: Debug in Circular_Linked_List (compiler: GNU GCC Compiler)---------------
Target is up to date. Nothing to be done (all items are up-to-date).
-------------- Run: Debug in Circular_Linked_List (compiler: GNU GCC Compiler)---------------
Checking for existence: C:\Users\hp\Desktop\CPP Programming\Circular_Linked_List\bin\Debug\Circular_Linked_List.exe Executing: "C:\Program Files (x86)\CodeBlocks/cb_console_runner.exe" "C:\Users\hp\Desktop\CPP Programming\Circular_Linked_List\bin\Debug\Circular_Linked_List.exe" (in C:\Users\hp\Desktop\CPP Programming\Circular_Linked_List.)
This is the following code which I'm trying to run and build on code::blocks17.12
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class Node
{
public:
int data;
Node *next;
};
void push(Node* head,int data)
{
Node *new_node = new Node();
Node *temp = head;
new_node->data = data;
new_node->next = head;
if(head!=NULL)
{
while(temp->next!=head)
{
temp = temp->next;
}
temp->next = new_node;
}
else{
new_node->next = new_node;
}
head = new_node;
}
void printList(Node* head)
{
Node *temp = head;
if(head!=NULL){
while(temp->next!=head)
{
cout<<temp->data<<" ";
temp=temp->next;
}
}
else{
return;
}
}
int main()
{
Node *head = NULL;
push(head,12);
push(head,14);
push(head,15);
push(head,16);
cout<<"Time to print the List\n";
printList(head);
return 0;
}