.CPP File Code
using namespace std; #include <stdlib.h> #include <iostream> struct StudentDetail{ string name; string vuid; }; //class Node* head; class Node{ struct StudentDetail newStd; class Node* next; class Node* prev; void Set(string name,string vuid) { newStd.name=name; newStd.vuid=vuid; } Node Get() { } void setNext(string name,string vuid){ if(next==NULL) { } else { class Node* newNode= new Node(); newStd.name=name; newStd.vuid=vuid; newNode->next= newNode; } } string getNext() { next; } void setPrev(string name,string vuid){ if(next==NULL) { } else { class Node* newNode= new Node(); newStd.name=name; newStd.vuid=vuid; newNode->next= newNode; } } string getPrev() { prev; } }; class DoublyLinkedList{ public: struct StudentDetail newStd; class DoublyLinkedList* headPtr; class DoublyLinkedList* curPtr; class DoublyLinkedList* nextPtr; int size; //dfdf class DoublyLinkedList* headDlinkList=NULL; void addAtBegining(string vuid, string name) { class DoublyLinkedList* dNode= new DoublyLinkedList(); dNode->newStd.vuid=vuid; dNode->newStd.name=name; dNode->nextPtr=headDlinkList; headDlinkList= dNode; dNode->curPtr=dNode; } void addAtEnd(string vuid, string name) { class DoublyLinkedList* dNode= new DoublyLinkedList(); dNode->newStd.vuid=vuid; dNode->newStd.name=name; dNode->nextPtr=headDlinkList; headDlinkList= dNode; dNode->curPtr=dNode; } void delNode() { class DoublyLinkedList* temp1=curPtr; class DoublyLinkedList* temp2= temp1; temp1->nextPtr= temp2->nextPtr; free(temp2); } void print() { class DoublyLinkedList* temp= headDlinkList; while(temp!=NULL) { cout<<temp->newStd.vuid<<" "<<temp->newStd.name<<endl; temp= temp->nextPtr; } } }; int main() { string vuid,name; cout<<"Add your vuID and Name at First Position "<<endl; cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl; DoublyLinkedList dlist1; cin>>vuid; cin>>name; dlist1.addAtBegining(vuid,name); dlist1.print(); cout<<"Insertion At Beginning in doubly Link List "<<endl; cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl; cin>>vuid; cin>>name; dlist1.addAtBegining(vuid,name); dlist1.print(); cout<<"Insertion At End in doubly Link List "<<endl; cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl; cin>>vuid; cin>>name; dlist1.addAtEnd(vuid,name); dlist1.print(); cout<<"Deletion of Current Node (Last Node) "<<endl; cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl; dlist1.delNode(); dlist1.print(); }The objective of this assignment is
-
o Binary Search trees
o AVL trees
o Rotation cases of AVL trees
o Balancing Factor of trees -
@zareen said in The objective of this assignment is:
o Binary Search trees
Binary Search Tree (BST) –
BST is a special type of binary tree in which left child of a node has value less than the parent and right child has value greater than parent. Consider the left skewed BST shown in Figure 2.
Searching: For searching element 1, we have to traverse all elements (in order 3, 2, 1). Therefore, searching in binary search tree has worst case complexity of O(n). In general, time complexity is O(h) where h is height of BST.
Insertion: For inserting element 0, it must be inserted as left child of 1. Therefore, we need to traverse all elements (in order 3, 2, 1) to insert 0 which has worst case complexity of O(n). In general, time complexity is O(h).
Deletion: For deletion of element 1, we have to traverse all elements to find 1 (in order 3, 2, 1). Therefore, deletion in binary tree has worst case complexity of O(n). In general, time complexity is O(h).


100% Off on Your FEE Join US! Ask Me How?


