diff --git a/DFS.cpp b/DFS.cpp index 187bdc5..46a8de2 100644 --- a/DFS.cpp +++ b/DFS.cpp @@ -1,80 +1,80 @@ -#include -using namespace std; - -// Graph class represents a directed graph -// using adjacency list representation -class Graph { - int V; // No. of vertices - - // Pointer to an array containing - // adjacency lists - list *adj; - - // A recursive function used by DFS - void DFSUtil(int v, bool visited[]); - -public: - Graph(int V); // Constructor - - // function to add an edge to graph - void addEdge(int v, int w); - - // DFS traversal of the vertices - // reachable from v - void DFS(int v); - -}; - -Graph::Graph(int V) { - this->V = V; - adj = new list[V]; -} - -void Graph::addEdge(int v, int w) { - adj[v].push_back(w); // Add w to v’s list. -} - -void Graph::DFSUtil(int v, bool visited[]) { - // Mark the current node as visited and - // print it - visited[v] = true; - cout << v << " "; - +#include +using namespace std; + +// Graph class represents a directed graph +// using adjacency list representation +class Graph { + int V; // No. of vertices + + // Pointer to an array containing + // adjacency lists + list *adj; + + // A recursive function used by DFS + void DFSUtil(int v, bool visited[]); + +public: + Graph(int V); // Constructor + + // function to add an edge to graph + void addEdge(int v, int w); + + // DFS traversal of the vertices + // reachable from v + void DFS(int v); + +}; + +Graph::Graph(int V) { + this->V = V; + adj = new list[V]; +} + +void Graph::addEdge(int v, int w) { + adj[v].push_back(w); // Add w to v’s list. +} + +void Graph::DFSUtil(int v, bool visited[]) { + // Mark the current node as visited and + // print it + visited[v] = true; + cout << v << " "; + // Recur for all the vertices adjacent neighbors - // to this vertex - for ( int neighbor : adj[v]){ - if (!visited[neighbor]){ + // to this vertex + for ( int neighbor : adj[v]) { + if (!visited[neighbor]) { DFSUtil(neighbor, visited); } } -} - -// DFS traversal of the vertices reachable from v. -// It uses recursive DFSUtil() -void Graph::DFS(int v) { - // Mark all the vertices as not visited - bool visited[V]; - +} + +// DFS traversal of the vertices reachable from v. +// It uses recursive DFSUtil() +void Graph::DFS(int v) { + // Mark all the vertices as not visited + bool visited[V]; + memset(visited, false, sizeof(visited)); - - // Call the recursive helper function - // to print DFS traversal - DFSUtil(v, visited); -} - -// Driver code -int main() { - // Create a graph given in the above diagram - Graph g(4); - g.addEdge(0, 1); - g.addEdge(0, 2); - g.addEdge(1, 2); - g.addEdge(2, 0); - g.addEdge(2, 3); - g.addEdge(3, 3); - + + // Call the recursive helper function + // to print DFS traversal + DFSUtil(v, visited); +} + +// Driver code +int main() { + // Create a graph given in the above diagram + Graph g(4); + g.addEdge(0, 1); + g.addEdge(0, 2); + g.addEdge(1, 2); + g.addEdge(2, 0); + g.addEdge(2, 3); + g.addEdge(3, 3); + cout << "Following is Depth First Traversal" - " (starting from vertex 2) \n"; - g.DFS(2); - - return 0; + " (starting from vertex 2) \n"; + g.DFS(2); + + return 0; diff --git a/DFS.cpp.orig b/DFS.cpp.orig new file mode 100644 index 0000000..187bdc5 --- /dev/null +++ b/DFS.cpp.orig @@ -0,0 +1,80 @@ +#include +using namespace std; + +// Graph class represents a directed graph +// using adjacency list representation +class Graph { + int V; // No. of vertices + + // Pointer to an array containing + // adjacency lists + list *adj; + + // A recursive function used by DFS + void DFSUtil(int v, bool visited[]); + +public: + Graph(int V); // Constructor + + // function to add an edge to graph + void addEdge(int v, int w); + + // DFS traversal of the vertices + // reachable from v + void DFS(int v); + +}; + +Graph::Graph(int V) { + this->V = V; + adj = new list[V]; +} + +void Graph::addEdge(int v, int w) { + adj[v].push_back(w); // Add w to v’s list. +} + +void Graph::DFSUtil(int v, bool visited[]) { + // Mark the current node as visited and + // print it + visited[v] = true; + cout << v << " "; + + // Recur for all the vertices adjacent neighbors + // to this vertex + for ( int neighbor : adj[v]){ + if (!visited[neighbor]){ + DFSUtil(neighbor, visited); + } + } +} + +// DFS traversal of the vertices reachable from v. +// It uses recursive DFSUtil() +void Graph::DFS(int v) { + // Mark all the vertices as not visited + bool visited[V]; + + memset(visited, false, sizeof(visited)); + + // Call the recursive helper function + // to print DFS traversal + DFSUtil(v, visited); +} + +// Driver code +int main() { + // Create a graph given in the above diagram + Graph g(4); + g.addEdge(0, 1); + g.addEdge(0, 2); + g.addEdge(1, 2); + g.addEdge(2, 0); + g.addEdge(2, 3); + g.addEdge(3, 3); + + cout << "Following is Depth First Traversal" + " (starting from vertex 2) \n"; + g.DFS(2); + + return 0; diff --git a/dataabstruction.cpp b/dataabstruction.cpp index 02a41c3..cafcb9a 100644 --- a/dataabstruction.cpp +++ b/dataabstruction.cpp @@ -1,20 +1,21 @@ -#include -using namespace std; - class Sum -{ -private: int x, y, z; // private variables are providing data abstraction in this program -public: -void add() -{ -cout<<"Enter two numbers: "; -cin>>x>>y; -z= x+y; -cout<<"Sum of two number is: "< +using namespace std; +class Sum +{ +private: + int x, y, z; // private variables are providing data abstraction in this program +public: + void add() + { + cout<<"Enter two numbers: "; + cin>>x>>y; + z= x+y; + cout<<"Sum of two number is: "< +using namespace std; + class Sum +{ +private: int x, y, z; // private variables are providing data abstraction in this program +public: +void add() +{ +cout<<"Enter two numbers: "; +cin>>x>>y; +z= x+y; +cout<<"Sum of two number is: "< data = value; - newNode -> prev = NULL; - if(head == NULL) + doublylist() { - newNode -> next = NULL; - head = newNode; + head=NULL; + tail=NULL; } - else + void addtohead(int value) { newNode -> next = head; head = newNode; @@ -129,136 +119,244 @@ void search_element(int data) { if(temp -> data == data) // Element is found { - - flag=1;//If found, print and exit - break; - + newNode -> next = NULL; + head = newNode; } else { - temp = temp ->next; //If not found, traverse the list - pos++; + newNode -> next = head; + head = newNode; } + cout<<"\nInsertion successful at the head"< data = v; + newNode -> next = NULL; + if(head == NULL) + { + newNode -> prev= NULL; + head = newNode; + } + else + { node *temp = head; + while(temp -> next != NULL) + temp = temp -> next; + temp -> next = newNode; + newNode -> prev = temp; + } + cout<<"\nInsertion success!!! at the end"<prev== temp->next) + { + head = NULL; + delete temp; + } + else { + head = temp->next; + head->prev = NULL; + delete temp; + } + cout<<"Deletion success at the front"<next; + if(head == NULL) + cout<<"List is Empty!!! Deletion not possible"<prev == temp->next) + { + head = NULL; + delete temp; + } + else { + while(temp->next != NULL) + temp = temp->next; + temp->prev ->next = NULL; + delete temp; + } + cout<<"Deletion successful at the end "<>loc; + temp=head; + for(int i=0; inext; + } + ptr->data = item; + ptr->next = temp->next; + ptr -> prev = temp; + temp->next = ptr; + temp->next->prev=ptr; + cout<<"Node Inserted at the desired position \n"; + } + } + void search_element(int data) { - deleteBeginning(); + node * temp = new node; + temp = head; + int pos = 0; + int flag=0; + while(temp != NULL) + { + if(temp -> data == data) // Element is found + { + + flag=1;//If found, print and exit + break; + + } + else + { + temp = temp ->next; //If not found, traverse the list + pos++; + } + } + if(flag==1) + { + cout<<"\nThe element is found in the list"; + } + else + { + cout<<"\nThe element is not found in the list"; + } } - else if(current != NULL) + void deleteFromN(int position) { - current->prev->next = current->next; - current->next->prev = current->prev; - delete current; - cout<<"SUCCESSFULLY DELETED NODE FROM POSITION.\n"; + node *current; + current = head; + for(int i=1; inext; + } + if(position == 0) + { + deleteBeginning(); + } + else if(current != NULL) + { + current->prev->next = current->next; + current->next->prev = current->prev; + delete current; + cout<<"SUCCESSFULLY DELETED NODE FROM POSITION.\n"; + } + else + { + cout<<"Invalid position!\n"; + } } - else + void reverse() { - cout<<"Invalid position!\n"; + node *current = head; + node *temp = NULL; + while(current!=NULL) + { + temp = current->prev; //swap the next and prev pointer + current->prev = current->next; + current->next = temp; + current = current->prev; + } + temp->prev; + cout<<"LIST REVERSED SUCCESSFULLY.\n"; } -} -void reverse() -{ - node *current = head; - node *temp = NULL; - while(current!=NULL) + void display() { - temp = current->prev; //swap the next and prev pointer - current->prev = current->next; - current->next = temp; - current = current->prev; + node *ptr; + cout<<"printing values"<data<<"->"<<" "; + ptr=ptr->next; + } } - temp->prev; - cout<<"LIST REVERSED SUCCESSFULLY.\n"; -} - void display() -{ - node *ptr; - cout<<"printing values"<data<<"->"<<" "; - ptr=ptr->next; - } -} }; int main() -{doublylist d; - while(1) - { int n; - cout<>n; - switch(n) - { - case 1: - int m; - cout<<"enter item to add to head"<>m; - d.addtohead(m); - break; - case 2: - int item; - cout<<"enter item to add to head"<>item; - d.insertAtEnd(item); - break; + cin>>n; + switch(n) + { + case 1: + int m; + cout<<"enter item to add to head"<>m; + d.addtohead(m); + break; + case 2: + int item; + cout<<"enter item to add to head"<>item; + d.insertAtEnd(item); + break; case 3: - d.deleteBeginning(); - break; - case 4: - d.deleteEnd(); - break; - case 5: - d.display(); - break; - case 6: - int newvalue; - cout<<"enter value for desired position\n"; - cin>>newvalue; - d.insert_specified(newvalue); - break; - case 7: - int newvalue1; - cout<<"enter value for searching position\n"; - cin>>newvalue1; - d.search_element(newvalue1); - break; - case 8: - int newvalue2; - cout<<"enter position desired for deletion \n"; - cin>>newvalue2; - d.deleteFromN(newvalue2); - break; - case 9: - d.reverse(); - break; - default: - cout<<"exit successfull";}} + d.deleteBeginning(); + break; + case 4: + d.deleteEnd(); + break; + case 5: + d.display(); + break; + case 6: + int newvalue; + cout<<"enter value for desired position\n"; + cin>>newvalue; + d.insert_specified(newvalue); + break; + case 7: + int newvalue1; + cout<<"enter value for searching position\n"; + cin>>newvalue1; + d.search_element(newvalue1); + break; + case 8: + int newvalue2; + cout<<"enter position desired for deletion \n"; + cin>>newvalue2; + d.deleteFromN(newvalue2); + break; + case 9: + d.reverse(); + break; + default: + cout<<"exit successfull"; + } + } } diff --git a/doubly_linkedlist.cpp.orig b/doubly_linkedlist.cpp.orig new file mode 100644 index 0000000..b5193c3 --- /dev/null +++ b/doubly_linkedlist.cpp.orig @@ -0,0 +1,264 @@ +#include +using namespace std; +struct node +{ + int data; + node *prev; + node *next; +}; + +class doublylist{ +private: + node *head,*tail; +public: + doublylist() + { + head=NULL; + tail=NULL; + } + void addtohead(int value) + { + node *newNode=new node; + newNode -> data = value; + newNode -> prev = NULL; + if(head == NULL) + { + newNode -> next = NULL; + head = newNode; + } + else + { + newNode -> next = head; + head = newNode; + } + cout<<"\nInsertion successful at the head"< data = v; + newNode -> next = NULL; + if(head == NULL) + { + newNode -> prev= NULL; + head = newNode; + } + else + { node *temp = head; + while(temp -> next != NULL) + temp = temp -> next; + temp -> next = newNode; + newNode -> prev = temp; + } + cout<<"\nInsertion success!!! at the end"<prev== temp->next) + { + head = NULL; + delete temp; + } + else{ + head = temp->next; + head->prev = NULL; + delete temp; + } + cout<<"Deletion success at the front"<prev == temp->next) + { + head = NULL; + delete temp; + } + else{ + while(temp->next != NULL) + temp = temp->next; + temp->prev ->next = NULL; + delete temp; + } + cout<<"Deletion successful at the end "<>loc; + temp=head; + for(int i=0;inext; + } + ptr->data = item; + ptr->next = temp->next; + ptr -> prev = temp; + temp->next = ptr; + temp->next->prev=ptr; + cout<<"Node Inserted at the desired position \n"; + } +} +void search_element(int data) +{ + node * temp = new node; + temp = head; + int pos = 0; + int flag=0; + while(temp != NULL) + { + if(temp -> data == data) // Element is found + { + + flag=1;//If found, print and exit + break; + + } + else + { + temp = temp ->next; //If not found, traverse the list + pos++; + } + } + if(flag==1) + { + cout<<"\nThe element is found in the list"; + } + else + { + cout<<"\nThe element is not found in the list"; + } +} +void deleteFromN(int position) +{ + node *current; + current = head; + for(int i=1; inext; + } + if(position == 0) + { + deleteBeginning(); + } + else if(current != NULL) + { + current->prev->next = current->next; + current->next->prev = current->prev; + delete current; + cout<<"SUCCESSFULLY DELETED NODE FROM POSITION.\n"; + } + else + { + cout<<"Invalid position!\n"; + } +} +void reverse() +{ + node *current = head; + node *temp = NULL; + while(current!=NULL) + { + temp = current->prev; //swap the next and prev pointer + current->prev = current->next; + current->next = temp; + current = current->prev; + } + temp->prev; + cout<<"LIST REVERSED SUCCESSFULLY.\n"; +} + void display() +{ + node *ptr; + cout<<"printing values"<data<<"->"<<" "; + ptr=ptr->next; + } +} +}; +int main() +{doublylist d; + while(1) + { int n; + cout<>n; + switch(n) + { + case 1: + int m; + cout<<"enter item to add to head"<>m; + d.addtohead(m); + break; + case 2: + int item; + cout<<"enter item to add to head"<>item; + d.insertAtEnd(item); + break; + case 3: + d.deleteBeginning(); + break; + case 4: + d.deleteEnd(); + break; + case 5: + d.display(); + break; + case 6: + int newvalue; + cout<<"enter value for desired position\n"; + cin>>newvalue; + d.insert_specified(newvalue); + break; + case 7: + int newvalue1; + cout<<"enter value for searching position\n"; + cin>>newvalue1; + d.search_element(newvalue1); + break; + case 8: + int newvalue2; + cout<<"enter position desired for deletion \n"; + cin>>newvalue2; + d.deleteFromN(newvalue2); + break; + case 9: + d.reverse(); + break; + default: + cout<<"exit successfull";}} +} diff --git a/encapsulation.cpp b/encapsulation.cpp index c9956f9..0f01b0b 100644 --- a/encapsulation.cpp +++ b/encapsulation.cpp @@ -1,7 +1,7 @@ #include using namespace std; -class ExampleEncap{ +class ExampleEncap { private: int num; char ch; @@ -27,4 +27,5 @@ int main(){ cout< +using namespace std; +class ExampleEncap{ +private: + int num; + char ch; +public: + int getNum() const { + return num; + } + char getCh() const { + return ch; + } + + void setNum(int num) { + this->num = num; + } + void setCh(char ch) { + this->ch = ch; + } +}; +int main(){ + ExampleEncap obj; + obj.setNum(100); + obj.setCh('A'); + cout<next = tmp; tail = tail->next; } cout<<"succesfully added to tail"; } - void addtohead(int val) - { node *new_node = new node; - new_node->data = val; - new_node->next = NULL; - if (head == NULL) - { - head = new_node; - } else - { - new_node->next = head; - head= new_node; - } - cout<<"succesfully added to head"; + void addtohead(int val) + { node *new_node = new node; + new_node->data = val; + new_node->next = NULL; + if (head == NULL) + { + head = new_node; + } else + { + new_node->next = head; + head= new_node; + } + cout<<"succesfully added to head"; } - void randominsert(int itemn) - { + void randominsert(int itemn) + { node *ptr = new node; - struct node *temp; - int loc; - cout<<"Enter the location"; - cin>>loc; - - ptr->data = itemn; - temp=head; - for(int i=0;inext; - if(temp == NULL) - { - cout<<"\ncan't insert\n"; - return; - } - } - ptr ->next = temp ->next; - temp ->next = ptr; - cout<<"\nNode inserted at desired position"; - } - void begdelete() - { - node *ptr; - if(head == NULL) - { - cout<<"\nList is empty"; - } - else - { - ptr = head; - head = ptr->next; - delete ptr; - cout<<"\n Node deleted from the begining ..."; - } - } -void end_delete() - { - struct node *ptr,*ptr1; - if(head == NULL) - { - cout<<"\nlist is empty"; - } - else if(head -> next == NULL) - { - head = NULL; - delete head; - cout<<"\nOnly node of the list deleted ..."; - } - else - { ptr = head; - while(ptr->next != NULL) - { - ptr1 = ptr; - ptr = ptr ->next; - } - ptr1->next = NULL; - delete ptr; - cout<<"\n Deleted Node from the last ..."; - } - } -void search(int key) -{ - struct node *search; - search=head; - while (search->next!= NULL) + struct node *temp; + int loc; + cout<<"Enter the location"; + cin>>loc; + + ptr->data = itemn; + temp=head; + for(int i=0; inext; + if(temp == NULL) + { + cout<<"\ncan't insert\n"; + return; + } + } + ptr ->next = temp ->next; + temp ->next = ptr; + cout<<"\nNode inserted at desired position"; + } + void begdelete() { - if (search->data == key) + node *ptr; + if(head == NULL) { - cout<<"element is found in list\n"; - return; + cout<<"\nList is empty"; + } + else + { + ptr = head; + head = ptr->next; + delete ptr; + cout<<"\n Node deleted from the begining ..."; } - search = search->next; - } - cout<<"item not found in list\n"; -} -void Delete(int anypos) -{ node* temp1 = head; - if(anypos == 1){ - head = temp1->next; - delete temp1; - cout<<"succesfully deleted from desired positon in list\n"< next == NULL) + { + head = NULL; + delete head; + cout<<"\nOnly node of the list deleted ..."; + } + else + { ptr = head; + while(ptr->next != NULL) + { + ptr1 = ptr; + ptr = ptr ->next; + } + ptr1->next = NULL; + delete ptr; + cout<<"\n Deleted Node from the last ..."; + } + } + void search(int key) { - temp1 = temp1->next; + struct node *search; + search=head; + while (search->next!= NULL) + { + if (search->data == key) + { + cout<<"element is found in list\n"; + return; + } + search = search->next; + } + cout<<"item not found in list\n"; } - node* temp2 = temp1->next; - temp1->next = temp2->next; - delete temp2; - cout<<"succesfully deleted from desired positon in list\n"<next; - curNode->next = head; - head = curNode; - curNode = nxtNode; + void Delete(int anypos) + { node* temp1 = head; + if(anypos == 1) { + head = temp1->next; + delete temp1; + cout<<"succesfully deleted from desired positon in list\n"<next; + } + node* temp2 = temp1->next; + temp1->next = temp2->next; + delete temp2; + cout<<"succesfully deleted from desired positon in list\n"<next; + curNode->next = head; + head = curNode; + curNode = nxtNode; + } + } + void display() { node *tmp; tmp = head; @@ -162,69 +162,69 @@ void display() } }; int main() -{ singlelist l; - int n; - while(1) - { cout<>n; - switch(n) -{ - case 1: - int item; - cout<<"enter item to tail"<>item; - l.addtotail(item); - break; - case 2: - int item1; - cout<<"enter item to tail"<>item1; - l.addtohead(item1); - break; - case 3: - int iteminsert; - cout<<"enter item to desired position"<>iteminsert; - l.randominsert(iteminsert); - break; - case 4: - l.begdelete(); - break; - case 5: - l.end_delete(); - break; - case 6: - int value; - cout<<"enter item you want to search"<>value; - l.search(value); - break; - case 7: - int delpos; - cout<<"enter position you want to delete"<>delpos; - l.Delete(delpos); - break; + cout<<"8. display"<>n; + switch(n) + { + case 1: + int item; + cout<<"enter item to tail"<>item; + l.addtotail(item); + break; + case 2: + int item1; + cout<<"enter item to tail"<>item1; + l.addtohead(item1); + break; + case 3: + int iteminsert; + cout<<"enter item to desired position"<>iteminsert; + l.randominsert(iteminsert); + break; + case 4: + l.begdelete(); + break; + case 5: + l.end_delete(); + break; + case 6: + int value; + cout<<"enter item you want to search"<>value; + l.search(value); + break; + case 7: + int delpos; + cout<<"enter position you want to delete"<>delpos; + l.Delete(delpos); + break; - case 8: - l.display(); - break; + case 8: + l.display(); + break; - case 9: - l.reverse(); - break; - default: - cout<<"nothing"< +using namespace std; +struct node +{ + int data; + node *next; +}; +class singlelist +{ + private: + node *tail,*head; + public: + singlelist() + { head=NULL; + tail=NULL; + } + void addtotail(int n) + { + node *tmp = new node; + tmp->data = n; + tmp->next = NULL; + if(head == NULL) + { + head = tmp; + tail = tmp; + }else + { + tail->next = tmp; + tail = tail->next; + } + cout<<"succesfully added to tail"; + } + void addtohead(int val) + { node *new_node = new node; + new_node->data = val; + new_node->next = NULL; + if (head == NULL) + { + head = new_node; + } else + { + new_node->next = head; + head= new_node; + } + cout<<"succesfully added to head"; + } + void randominsert(int itemn) + { + node *ptr = new node; + struct node *temp; + int loc; + cout<<"Enter the location"; + cin>>loc; + + ptr->data = itemn; + temp=head; + for(int i=0;inext; + if(temp == NULL) + { + cout<<"\ncan't insert\n"; + return; + } + } + ptr ->next = temp ->next; + temp ->next = ptr; + cout<<"\nNode inserted at desired position"; + } + void begdelete() + { + node *ptr; + if(head == NULL) + { + cout<<"\nList is empty"; + } + else + { + ptr = head; + head = ptr->next; + delete ptr; + cout<<"\n Node deleted from the begining ..."; + } + } +void end_delete() + { + struct node *ptr,*ptr1; + if(head == NULL) + { + cout<<"\nlist is empty"; + } + else if(head -> next == NULL) + { + head = NULL; + delete head; + cout<<"\nOnly node of the list deleted ..."; + } + else + { ptr = head; + while(ptr->next != NULL) + { + ptr1 = ptr; + ptr = ptr ->next; + } + ptr1->next = NULL; + delete ptr; + cout<<"\n Deleted Node from the last ..."; + } + } +void search(int key) +{ + struct node *search; + search=head; + while (search->next!= NULL) + { + if (search->data == key) + { + cout<<"element is found in list\n"; + return; + } + search = search->next; + } + cout<<"item not found in list\n"; +} +void Delete(int anypos) +{ node* temp1 = head; + if(anypos == 1){ + head = temp1->next; + delete temp1; + cout<<"succesfully deleted from desired positon in list\n"<next; + } + node* temp2 = temp1->next; + temp1->next = temp2->next; + delete temp2; + cout<<"succesfully deleted from desired positon in list\n"<next; + curNode->next = head; + head = curNode; + curNode = nxtNode; + } +} +void display() + { + node *tmp; + tmp = head; + while (tmp != NULL) + { + cout << tmp->data <<"->"<<" "; + tmp = tmp->next; + } + } +}; +int main() +{ singlelist l; + int n; + while(1) + { cout<>n; + switch(n) +{ + case 1: + int item; + cout<<"enter item to tail"<>item; + l.addtotail(item); + break; + case 2: + int item1; + cout<<"enter item to tail"<>item1; + l.addtohead(item1); + break; + case 3: + int iteminsert; + cout<<"enter item to desired position"<>iteminsert; + l.randominsert(iteminsert); + break; + case 4: + l.begdelete(); + break; + case 5: + l.end_delete(); + break; + case 6: + int value; + cout<<"enter item you want to search"<>value; + l.search(value); + break; + case 7: + int delpos; + cout<<"enter position you want to delete"<>delpos; + l.Delete(delpos); + break; + + case 8: + l.display(); + break; + + case 9: + l.reverse(); + break; + default: + cout<<"nothing"< +#include using namespace std; void merge(int *a,int s,int e){ diff --git a/statickeyword.cpp b/statickeyword.cpp index 19c0c9c..07008c4 100644 --- a/statickeyword.cpp +++ b/statickeyword.cpp @@ -1,28 +1,28 @@ #include using namespace std; - class mayank - { +class mayank +{ - public: - static int count; - mayank() - { - count++; - } - static int display() - { - cout<<"no of objects"< +using namespace std; + class mayank + { + + public: + static int count; + mayank() + { + count++; + } + static int display() + { + cout<<"no of objects"<num =num; - this->ch=ch; - } - void displayMyValues(){ - cout<num =num; + this->ch=ch; + } + void displayMyValues() { + cout< +using namespace std; +class Demo { +private: + int num; + char ch; +public: + void setMyValues(int num, char ch){ + this->num =num; + this->ch=ch; + } + void displayMyValues(){ + cout<