Posts

Telephone Directory Using BST

Source Code: #include <iostream> #include <string> using namespace std; struct phone{  int Num;  int code; string address; string name; phone*right; phone*left; };phone*root=NULL; phone*nodeptr=NULL; //insert void insert(string nme,string add, int phno,int Code) { phone*p=new phone; p->name=nme; p->address=add; p->Num=phno; p->code=Code; p->right=NULL; p->left=NULL; if(root==NULL) { root=p; cout<<"PHone nUmber is saved \n"; } else {       nodeptr=root; while(nodeptr!=NULL) { if(phno<nodeptr->Num) { if(nodeptr->left!=NULL) { nodeptr=nodeptr->left; } else { nodeptr->left=p; cout<<"PHone nUmber is saved \n"; break; } } else if(phno>nodeptr->Num) { if(nodeptr->right!=NULL) { nodeptr=nodeptr->ri...

Data Structure LAb 10

Source Code: #include <iostream> using namespace std; struct tree { int num; tree*left=NULL; tree*right=NULL; };tree*root=NULL; tree*nodeptr=NULL; //add tree void add(int n) { tree* t=new tree; t->num=n; t->left=NULL; t->right=NULL; bool flag=false; if(root==NULL) { root=t; flag=true; } else { nodeptr=root; while(nodeptr!=NULL) { if(n<nodeptr->num) { if(nodeptr->left!=NULL) { nodeptr=nodeptr->left; } else { nodeptr->left=t; flag=true; break; } } else if(n>nodeptr->num) { if(nodeptr->right!=NULL) { nodeptr=nodeptr->right; } else { flag=true; nodeptr->right=t; break; } } else { cout<<"Duplicate NUmber \n"; break; } } } if(flag==true) cout<<"Va...

Circular Linked List

Source code: #include <iostream> using namespace std; struct node{ int num; node*next; };node*head=NULL; node*temp=NULL; void add(int n) { bool flag=false; node*newnode=new node; newnode->num=n; if(head==NULL) { head=newnode; newnode->next=head; flag=true; } else { temp=head; while(temp->next!=head) { temp=temp->next; } temp->next=newnode; newnode->next=head; flag=true; } if(flag==true) cout<<"value is entered \n"; else cout<<"Error \n"; } void Delete() { bool flag=false; node*temp2=NULL; if(head==NULL) { cout<<"list is empty \n"; } else if(head->next==head) { head->next=NULL; head=NULL; delete head; flag=true; } else { temp=head; while(temp->next!=head) { temp2=temp; temp=temp->next; } temp2->next=head; delete temp; flag=true; } if(flag==true) cout<<"value is Deleted \n"; else cout<<"E...

Data Structure Theory Assignment 2

Question#1 a)       What are the advantages of doubly linked list over singly linked list? Advantages over singly linked list 1) A DLL can be traversed in both forward and backward direction. 2) The delete operation in DLL is more efficient if pointer to the node to be deleted is given. In singly linked list, to delete a node, pointer to the previous node is needed. To get this  previous node, sometimes the list is traversed. In DLL, we can get the previous node using previous pointer. a)       What’s the difference between singly, doubly and circular linked list? Singly linked list A singly linked list is a linked list where the node contains some data and a pointer to the next node in the list It allows traversal only in one way It uses less memory per node (single pointer) Doubly A doubly linked list is complex type of linked list where the node contains some data and a pointer to the next as well as the...

Data STructure LAb 9

#include <iostream> using namespace std; void merge(int left[],int right[],int arr[],int mid,int lengthmid); int count=0; //factorial int fact(int n) {     if(n==0)     return 1;     else     return fact(n-1)*n; } int fibon(int n) {     if(n==0)     return 0;         if(n==1)         return 1;         else         return fibon(n-2)+fibon(n-1); } //merge sort void mergesort(int arr[],int low,int high) {     int length=low+high;     int mid=length/2;     int left[mid];     int right[length-mid];     if(length<2)     return ;     for(int i=0;i<mid;i++)     left[i]=arr[i];     for(int j=mid;j<length;j++)     right[j-mid]=a...

LIBRARY MANAGEMENT SYSTEM USING SINGLY LINK LIST

#include <iostream> #include <ctime> #include <fstream> #include <string> #include <ctime> using namespace std; string BookName,StdName; int countBook=0,countissuebook=0; //structure of book struct Book { string name; Book*next= NULL; }*head=NULL; //structure of issuing  book struct issuebook{ string stdname;     string bookname;     string issuedate;     string duedate;     int no_of_book_issued_to_student;     issuebook *next;  }*head1=NULL; //insert a book bool insertbook(string Name,char* time) { bool flag=false; ofstream myfile("books.txt",ofstream::out | ofstream::app); Book *newBook= new Book; Book *temp; countBook++; newBook->name =Name; newBook->next=NULL; if(head==NULL) { head=newBook; flag=true; } else { temp=head; while(temp->next!=NULL) { temp=temp->next; } temp->next=newBook; flag=true; ...

Data Structure lab 8

Image
Source code: #include <iostream> using namespace std; struct Node{ int  num; Node* next; Node*prev; };Node*head=NULL; Node*temp=NULL; //insert at end void add(int n) { Node * newnode=new Node; newnode->num=n; newnode->next=NULL; newnode->prev=NULL;   if(head==NULL)   {   head=newnode;   cout<<"Enter Sucessful \n";   }   else   {   temp=head;   while(temp->next!=NULL)   {   temp=temp->next;   }   temp->next=newnode;   newnode->prev=temp;   cout<<"Enter Sucessful \n";   }    } //delete at end void Delete() { temp=head; { while(temp->next!=NULL) { temp=temp->next; } temp->prev->next=NULL; delete temp; } } //display void display() { temp=head; while(temp->next!=NULL) { cout<<temp->num...