PROGRAM TO IMPLEMENT CIRCULAR LIST.
#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
class C_List;
class Node
{
private:
int Info;
Node *Link;
friend class C_List;
};
class C_List
{
private:
Node *Last;
public:
C_List()
{
Last = NULL;
}
void Insert(int Value)
{
Node *Temp = new Node;
Temp->Info = Value;
if (IsEmpty())
Last = Temp;
else
Temp->Link = Last->Link;
Last->Link = Temp;
Last = Temp;
}
void Print()
{
Node *Temp = new Node;
if(IsEmpty())
{
cout << "\nLIST IS EMPTY...!!!\n" << endl;
exit(1);
}
for(Temp = Last->Link; Temp != Last; Temp = Temp->Link)
cout << Temp->Info << endl;
cout << Temp->Info << endl;
}
void Delet()
{
Node *Temp = new Node;
if (IsEmpty())
{
cout << "\nLIST IS EMPTY.....!!!\n" << endl;
exit(1);
}
Temp = Last->Link;
if (Last == Temp)
Last = NULL;
else
Last->Link = Temp->Link;
delete Temp;
}
inline bool IsEmpty()
{
return Last == NULL;
}
};
int main()
{
C_List Obj;
Obj.Insert(1);
Obj.Insert(2);
Obj.Insert(3);
Obj.Insert(4);
Obj.Insert(5);
Obj.Print();
Obj.Delet();
Obj.Delet();
Obj.Delet();
Obj.Delet();
Obj.Delet();
getch();
return 0;
}
0 comments:
Post a Comment