Hi,
I am confused in making circular linked list.
This is what I have.
CircularLinkedList.h
#ifndef CircularLinkedList_H
#define CircularLinkedList_H
class CircularLinkedList
{
public:
void remove();
void set_number_people(int);
void print();
};
#endif
CircularLinkedList.cpp
#include "CircularLinkedList.h"
#include "Node.h"
#include <stdio.h>
void CircularLinkedList::set_number_people(int num_people) //This is where I am confused
{
Node *head = new Node;
int n = num_people;
Node *temp = new Node;
*head->set_next(*temp);
for(int x = 2; x < n; x++)
{
}
}
Node.h
#ifndef Node_H
#define Node_H
#include<stdio.h>
class Node
{
public:
void set_data(int data)
{
this->data = data;
}
void set_next(Node temp)
{
temp.next = new Node;
}
int get_data(Node temp)
{
return temp->data; //'->Node::data' : left operand has 'class' type,
//use '.'
}
Node get_next(Node temp)
{
return temp->next;
}
private:
int data;
Node *next;
};
#endif
driver.cpp
#include<iostream>
#include "CircularLinkedList.h"
using namespace std;
int main()
{
int people, count;
cout<<"Enter number of people: ";
cin>>people;
cout<<"Enter number of counts: ";
cin>>count;
CircularLinkedList cclist;
cclist.set_number_people(people);
//cclist.print();
return 0;
}
Initially I had made one method of making circular linked list in node class which is
Node link(int num_people)
{
int n = num_people;
Node *head = new Node;
head->data = 1;
head->next = new Node;
head->next->data = 2;
Node *temp = head->next;
for(int x = 2; x <= n; x++)
{
temp->next = new Node;
temp->next->data = x;
temp = temp->next;
if(x == n)
{
temp = NULL;
}
}
if(temp == NULL)
{
temp = head;
}
return *head;
}
But now I am confused in making the cirular linked list in Circularlinkedlist class not in Node.
Thanks in advance.