Posts

Showing posts from April, 2018

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...

Data Structure Lab 7

Image
Source Code: #include <iostream> using namespace std; struct Node{ int id; Node*next; // Node*head = NULL; }; Node* head = NULL; Node* temp=NULL; //menu void menu() { cout << "***************************************** \n"; cout << "1: Insert an Element at front \n"; cout << "2: delete an Elemnet from end \n"; cout << "3: Search an element \n"; cout << "4: Display list \n"; cout << "5: Is List empty \n"; cout << "6: Exit \n "; cout << "***************************************** \n"; cout<< " Enter Your  choice: "; } //insert at start void InsertAtStart(int x) { Node*newnode = new Node; newnode->id = x; newnode->next = NULL; if (head == NULL) { head = newnode; cout<<"Value is entered in linked list \n "; } else ...

DS Lab quiz 1

There are n cars at a gas station .Every time a new car arrive it joins the line from the end.the car came from first served fist.implement a linked list based solution in order to record the information.Store the following properties of car in your linked list. Car plate No Car Model Car's position in the line your solution must be contain following functions. Add the information of a car. update car info display the total size. Source Code: #include <iostream> using namespace std; struct car{ string CplateNo; int model; int carposition; car*next; };car *head=NULL; car* temp=NULL; string cno; int mod,cp=0,sizecount=0; //add void add(string Carno,int carmod) { bool flag=false; car* c=new car; c->carposition=cp++; c->CplateNo=Carno; c->model =carmod; c->next=NULL; if(head==NULL) { sizecount++; head=c; cout<<"Information is entered"<<endl; ...

Data Structure Lab 6

Image
Source code : #include <iostream> using namespace std; #define size 5 int que[size],front=0,rear=0; //add value in enque void enque(int value) { if(size==rear && front==0) { cout<<"Qeue is full"<<endl; } else { que[rear]=value; rear++; cout<<value<<" value is enqeue in array"<<endl; } } //del value from que void deque() { int no; if(front==rear) { cout<<"Stack is empty"<<endl; } else { no=que[front]; front++; cout<<no<<" is deleted from que. "<<endl; } } void display() { if(front==rear) { cout<<"Stack is empty"<<endl; } else { for(int i=front;i<rear;i++) { cout<<que[i]<<"  "; } cout<<endl; } } int main() { int choice,value; do{ cout<<"****...