Code:#include <iostream> #include <conio.h> using namespace std; struct Node { int data; Node *nextptr; }; class CLLIST{ private: Node*firstptr; Node*lastptr; public: CLLIST(){ cout << "Constructor Called !"; firstptr=lastptr=NULL; } void insert_at_back(int val){ if(firstptr==NULL) //it means start of C.LIST { firstptr = new Node; firstptr->data=val; firstptr->nextptr=firstptr; } else{ Node*temp1; Node*temp2; temp1 = firstptr; temp2 = temp1->nextptr; temp2->data = val; //inserted at back temp2->nextptr=firstptr; //circle completed } } void printit(){ // functiont o print all the circular link lists data Node* temp3ptr; temp3ptr = firstptr; while(temp3ptr->nextptr!=firstptr)//traversing { cout << temp3ptr->data; cout << endl; } } // 1-return pointer to node give the index positio of node is list Null if node dosent exist void pointer_to_node(int value){ Node*temp4ptr; temp4ptr = firstptr; int count = 0; while(temp4ptr->nextptr != firstptr) //traversing { if(count == value){ cout << "Your Required Pointer is : \n"; cout << "Index No: " << value; cout << temp4ptr; } count++; } temp4ptr = NULL; cout << "Can't You Think in Bounds"; cout <<temp4ptr; } //2-call the size of lise int size_of_list(){ Node*temp5ptr; temp5ptr = firstptr; int size = 0; //size calculating variable while(temp5ptr->nextptr !=firstptr) { size++; } cout << "Size if : "; cout << size; return(size); } // B-Value to be inserted at the end of node: void insert_value(int value2){ if(firstptr==NULL) //it means starts of C.LIST { Node*temptr; firstptr = temptr; firstptr->data = value2; firstptr->nextptr=firstptr; } else { Node*temptr1; Node*temptr2; temptr1 = firstptr; while(temptr1->nextptr != firstptr) //traversing { temptr2 = temptr1->nextptr;//inserted temptr2->nextptr = firstptr; //circle completed } } } }; int main() { CLLIST obj1; obj1.insert_at_back(25); obj1.insert_value(23); obj1.size_of_list(); obj1.printit(); cout << " \n \n Done !"; getch(); }




Reply With Quote