diff --git a/data_structures/C++/BubbleSort.c b/data_structures/C/BubbleSort.c similarity index 100% rename from data_structures/C++/BubbleSort.c rename to data_structures/C/BubbleSort.c diff --git a/data_structures/C++/BinarySearchTree.cpp b/data_structures/Cpp/BinarySearchTree.cpp similarity index 100% rename from data_structures/C++/BinarySearchTree.cpp rename to data_structures/Cpp/BinarySearchTree.cpp diff --git a/data_structures/C++/CIRCULAR_LINKED_LIST_C++.CPP b/data_structures/Cpp/CIRCULAR_LINKED_LIST_C++.CPP similarity index 94% rename from data_structures/C++/CIRCULAR_LINKED_LIST_C++.CPP rename to data_structures/Cpp/CIRCULAR_LINKED_LIST_C++.CPP index e0ff3ce4..b34920c3 100644 --- a/data_structures/C++/CIRCULAR_LINKED_LIST_C++.CPP +++ b/data_structures/Cpp/CIRCULAR_LINKED_LIST_C++.CPP @@ -1,167 +1,167 @@ -#include -using namespace std; - int size; - -struct Node -{ - int data; - struct Node *next; -}*first=NULL,*last=NULL; -void create() -{ - struct Node *t; - first=new Node; - last =new Node; - cout<<"enter size of linked list"<>size; - cout<<"enter elements"<>first->data; - first->next=first; - last=first; - - - - for(int i=2;i<=size;i++) - { t=new Node; - cin>>t->data; - t->next=last->next; - last->next=t; - last=t; - } - - -} -void Display(struct Node *p) -{ - do - { - cout<data<<" "<next; - }while(p!=first); -} -void insert(struct Node *p,int pos,int x) -{ - Node *t; - if(pos==1) - { - t=new Node; - t->data=x; - if(first==NULL) - { - first=t; - first->next=first; - } - else - { - p=first; - while(p->next!=first) - p=p->next; - p->next=t; - t->next=first; - first=t; - } - } - else - { - p=first; - for(int i=1;inext; - t=new Node; - t->data=x; - t->next=p->next; - p->next=t; - - } -} -int search(struct Node *p,int el) -{ int flag=0; - do - { - if(p->data==el) - { - flag=1; - return flag; - break; - } - else - flag=0; - p=p->next; - }while(p!=first); - return flag; -} -int del(struct Node *p,int pos) -{ struct Node *q; - int x=-1; - if(pos==1) - { - p=first; - while(p->next!=first) - p=p->next; - x=first->data; - if(p==first) - { - delete first; - first=NULL; - } - else - { - p->next=first->next; - q=first; - first=first->next; - delete q; - - } - - } - else - { - p=first; - for(int i=1;inext; - q=p->next; - x=q->data; - delete q; - } - return x; -} -int main() -{ int choice; - cout<<"......MENU......."<>choice; - switch(choice) - { - case 1: create();break; - case 2: Display(first);break; - case 3: int el,pos; - cout<<"enter position and element"<>pos>>el; - insert(first,pos,el);break; - case 4: int searchel; - cout<<"enter element to be searched:"; - cin>>searchel; - int z; - z=search(first,searchel); - if(z==1) - cout<<"search successful"<>pos1; - int y; - y=del(first,pos1); - cout<0); - return 0; -} +#include +using namespace std; + int size; + +struct Node +{ + int data; + struct Node *next; +}*first=NULL,*last=NULL; +void create() +{ + struct Node *t; + first=new Node; + last =new Node; + cout<<"enter size of linked list"<>size; + cout<<"enter elements"<>first->data; + first->next=first; + last=first; + + + + for(int i=2;i<=size;i++) + { t=new Node; + cin>>t->data; + t->next=last->next; + last->next=t; + last=t; + } + + +} +void Display(struct Node *p) +{ + do + { + cout<data<<" "<next; + }while(p!=first); +} +void insert(struct Node *p,int pos,int x) +{ + Node *t; + if(pos==1) + { + t=new Node; + t->data=x; + if(first==NULL) + { + first=t; + first->next=first; + } + else + { + p=first; + while(p->next!=first) + p=p->next; + p->next=t; + t->next=first; + first=t; + } + } + else + { + p=first; + for(int i=1;inext; + t=new Node; + t->data=x; + t->next=p->next; + p->next=t; + + } +} +int search(struct Node *p,int el) +{ int flag=0; + do + { + if(p->data==el) + { + flag=1; + return flag; + break; + } + else + flag=0; + p=p->next; + }while(p!=first); + return flag; +} +int del(struct Node *p,int pos) +{ struct Node *q; + int x=-1; + if(pos==1) + { + p=first; + while(p->next!=first) + p=p->next; + x=first->data; + if(p==first) + { + delete first; + first=NULL; + } + else + { + p->next=first->next; + q=first; + first=first->next; + delete q; + + } + + } + else + { + p=first; + for(int i=1;inext; + q=p->next; + x=q->data; + delete q; + } + return x; +} +int main() +{ int choice; + cout<<"......MENU......."<>choice; + switch(choice) + { + case 1: create();break; + case 2: Display(first);break; + case 3: int el,pos; + cout<<"enter position and element"<>pos>>el; + insert(first,pos,el);break; + case 4: int searchel; + cout<<"enter element to be searched:"; + cin>>searchel; + int z; + z=search(first,searchel); + if(z==1) + cout<<"search successful"<>pos1; + int y; + y=del(first,pos1); + cout<0); + return 0; +} diff --git a/data_structures/C++/CountNodes.cpp b/data_structures/Cpp/CountNodes.cpp similarity index 100% rename from data_structures/C++/CountNodes.cpp rename to data_structures/Cpp/CountNodes.cpp diff --git a/data_structures/C++/Queue_C++.cpp b/data_structures/Cpp/Queue_C++.cpp similarity index 100% rename from data_structures/C++/Queue_C++.cpp rename to data_structures/Cpp/Queue_C++.cpp diff --git a/data_structures/C++/circular_queue.cpp b/data_structures/Cpp/circular_queue.cpp similarity index 100% rename from data_structures/C++/circular_queue.cpp rename to data_structures/Cpp/circular_queue.cpp diff --git a/data_structures/C++/circularqueue.cpp b/data_structures/Cpp/circularqueue.cpp similarity index 100% rename from data_structures/C++/circularqueue.cpp rename to data_structures/Cpp/circularqueue.cpp diff --git a/data_structures/C++/detect_cycle_dfs.cpp b/data_structures/Cpp/detect_cycle_dfs.cpp similarity index 100% rename from data_structures/C++/detect_cycle_dfs.cpp rename to data_structures/Cpp/detect_cycle_dfs.cpp diff --git a/data_structures/C++/doubly_linkedlist.cpp b/data_structures/Cpp/doubly_linkedlist.cpp similarity index 94% rename from data_structures/C++/doubly_linkedlist.cpp rename to data_structures/Cpp/doubly_linkedlist.cpp index 9517e45d..ae8bffc2 100644 --- a/data_structures/C++/doubly_linkedlist.cpp +++ b/data_structures/Cpp/doubly_linkedlist.cpp @@ -1,92 +1,92 @@ -#include -using namespace std; - -class Node{ -public: - int data; - Node* prev; - Node* next; -}; - -Node* head=NULL; //initially head is null; - -Node* MakeNewNode(int x) { - Node* newNode= new Node(); //new operator creates memory space - newNode->data=x; - newNode->prev=NULL; - newNode->next=NULL; - return newNode; -} - -//Inserts a Node at head of doubly linked list -void InsertAtHead(int x){ - Node* newNode=MakeNewNode(x); - if(head == NULL){ - head = newNode; - return; - } - head->prev=newNode; - newNode->next=head; - head=newNode; -} - -void InsertAtTail(int x){ - Node* temp=head; - Node* newNode=MakeNewNode(x); - if(head==NULL){ - head=newNode; - return; - } - while(temp->next!=NULL) - temp = temp->next; // Go To last Node - temp->next = newNode; - newNode->prev = temp; -} - -//prints all nodes starting from head till we find NULL -void Print(){ - Node* temp=head; - while(temp!=NULL){ - cout<data<<" "; - temp = temp->next; - } - cout<next!=NULL){ - temp=temp->next; - } - //now from last we go backwards - while(temp!=NULL) { - cout<data<<" "; - temp=temp->prev; - } - cout< +using namespace std; + +class Node{ +public: + int data; + Node* prev; + Node* next; +}; + +Node* head=NULL; //initially head is null; + +Node* MakeNewNode(int x) { + Node* newNode= new Node(); //new operator creates memory space + newNode->data=x; + newNode->prev=NULL; + newNode->next=NULL; + return newNode; +} + +//Inserts a Node at head of doubly linked list +void InsertAtHead(int x){ + Node* newNode=MakeNewNode(x); + if(head == NULL){ + head = newNode; + return; + } + head->prev=newNode; + newNode->next=head; + head=newNode; +} + +void InsertAtTail(int x){ + Node* temp=head; + Node* newNode=MakeNewNode(x); + if(head==NULL){ + head=newNode; + return; + } + while(temp->next!=NULL) + temp = temp->next; // Go To last Node + temp->next = newNode; + newNode->prev = temp; +} + +//prints all nodes starting from head till we find NULL +void Print(){ + Node* temp=head; + while(temp!=NULL){ + cout<data<<" "; + temp = temp->next; + } + cout<next!=NULL){ + temp=temp->next; + } + //now from last we go backwards + while(temp!=NULL) { + cout<data<<" "; + temp=temp->prev; + } + cout<