I am trying to make a circular linked list and I think I am not linking it properly in the middle area because I can print the last and first node, but not the rest...
#include <iostream>
#include <new>
using namespace std;
struct node
{ int Item;
node* Next;
}; // end struct
typedef node* ptrType;
ptrType Head = NULL; // for zero-length list
ptrType Temp, Last;
// create circular list of n elements
void add()
{
int n;
cout << "What is n? ";
cin >> n;
if (n > 0)
{
Head = new(node);
Head -> Item = n;
Temp = Head->Next;
for (int i = n; i >= 1; i--)
{
Temp = new(node);
Temp -> Item = i;
Temp -> Next = Temp;
Last = Temp;
}
Last -> Next = Head; // to make the list circular
}
else; // do nothing, n == 0 means list is empty
}
void print_circle(ptrType Head)
{
if(Head!=NULL)
{
cout << Last->Next->Item;
cout << Last->Item;
cout << Last->Next->Next->Item;//problem is here!@!@!
ptrType First = Last -> Next;
Temp = First;
while(Temp != First)
{
cout << Temp -> Item << endl;
Temp = Temp -> Next;
}
}
}
int main()
{
add();
print_circle(Head);
cout << "\nran through functions";
char end;
cin >> end;
return 0;
}