I am Passionate developer and esthetic keen for learning new technologies. I am Familial with technologies like unity, java, python, c, c++, dart, flutter, linux, and cyber-security. I am fascinated by the technologies and now looking forward to learn them.
#include <iostream>
using namespace std;
//CODE FOR SELF CREATING STRUCTURE
struct Node{
int id;
Node *prev;
Node *next;
int data;
};
/******************************************************************************/
//CREATING CLASS OR FINGER PRINT OF OBJECT
class ListCircularDouble{
public:
//CREATING GOLBAL POINTER FOR OBJECT;
Node *start, *previous, *node;
//ID FOR CREATING ARRAY LIKE BEHAVIOR
int id=0;
//SOME IMPORT INITIALIZTION WHILE CALLING CONSTRUCTOR
ListCircularDouble(int data){
node=new Node;
start=node;
previous=node;
previous->prev=node;
previous->next=node;
node->data=data;
start->id=id;
cout<<"id Number "<<id<<"="<<data<<endl;
}
//ADD ELEMENT IN START
void addAtStart(int data){
cout<<"id Number "<<id+1<<"="<<data<<endl;
id=id+1;
cout<<id<<endl;
node=new Node;
node->data=data;
node->id=id;
previous->next=node;
node->prev= previous;
start->prev=node;
node->next=start;
previous=node;
};
//DISPLAY LIST
void display(){
Node *ptr=start;
do {
cout<<ptr->id<<"-> "<<ptr->data<<", ";
ptr=ptr->next;
} while(ptr!=start);
cout<<endl;
};
//ADD MULTIPLE ELEMENT WHERE N IS NUMBER OF ELEMENT
void createListInt(int n){
cout<< "Add "<<n<<" Elements"<<endl;
int data;
for ( int i = 0; i < n; i ++ ) {
cin>>data;
this->addAtEnd (data);
}
};
};
int main(){
//Create At least 1 element By creating OBj
ListCircularDouble list1(2);
//ADD ELEMNTS
list1.addAtStatt (20);
list1.addAtStart (30);
list1.display();
}