PROGRAM TO IMPLEMENT CIRCULAR LISTS(function del after).
#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 Delet_After(Node *Temp)
{
if(IsEmpty() || Temp == Temp->Link)
{
cout << "DELETION IS NOT POSSIBLE...!!!" << endl;
exit(1);
}
Node *Test = Temp->Link;
cout << "\nValue to be Deleted is: " << Temp->Info << endl;
Temp->Link = Test->Link;
delete(Test);
}
void Delete(C_List Obj)
{
Delet_After(Obj.Last);
}
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.Delete(Obj);
getch();
return 0;
}
0 comments:
Post a Comment