>may i know how do i implement the circular linked list?
Quick and dirty:
#include <iostream>
using namespace std;
struct node {
int data;
node *next;
node ( int init, node *link )
: data ( init ), next ( link )
{}
};
int main()
{
node *list = new node ( -1, 0 );
node *it = list;
list->next = list;
for ( int i = 0; i < 10; i++ ) {
it->next = new node ( i, list );
it = it->next;
}
it = list->next;
for ( int i = 0; i < 5; it = it->next ) {
if ( it->data == -1 ) {
cout<<endl;
++i;
}
else
cout<< it->data <<"->";
}
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Please don't just blanketly post your homework assignments. We're not here to do your work for you. Post your own code, and we'll help you troubleshoot it. Additionally, we encourage members not to do your assignments for you, as they are contributing to you not learning anything.
We're here to help you learn, not to cheat.
alc6379
Cookie... That's it
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147