Hulas Ds Record
Hulas Ds Record
Hulas Ds Record
Aim:
Algorithm:
Code:
#include<iostream>
class Tree
public:
int data;
data = x;
left = NULL;
right = NULL;
};
if (root ==
NULL) return;
preorder_traversal (root->left);
preorder_traversal (root->right);
if (root ==
NULL) return;
inorder_traversal (root->left);
inorder_traversal (root->right);
}
if (root ==
NULL) return;
postorder_traversal (root->left);
postorder_traversal (root->right);
int main ()
preorder_traversal (root);
inorder_traversal (root);
cout << endl;
postorder_traversal (root);
return 0;
OUTPUT:
RESULT:
PROGRAM 15:
Aim:
Algorithm:
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
/*
* Node Declaration
*/
struct node
int priority;
int info;
};
/*
*/
class Priority_Queue
private:
node *front;
public:
Priority_Queue()
front = NULL;
/*
*/
void insert(int item, int priority)
tmp->info =
item;
tmp->priority = priority;
tmp->link = front;
front = tmp;
else
q = front;
priority) q=q->link;
tmp->link = q-
>link; q->link =
tmp;
/*
* Delete from Priority Queue
*/
void del()
node *tmp;
if(front == NULL)
cout<<"Queue Underflow\n";
else
tmp = front;
front = front->link;
free(tmp);
/*
*/
void display()
node *ptr;
ptr = front;
if (front == NULL)
cout<<"Queue is empty\n";
else
{ cout<<"Queue is :\n";
cout<<"Priority Item\n";
while(ptr != NULL)
cout<<ptr->priority<<" "<<ptr->info<<endl;
ptr = ptr->link;
};
/*
* Main
*/
int main()
Priority_Queue pq;
do
cout<<"1.Insert\n";
cout<<"2.Delete\n";
cout<<"3.Display\n";
cout<<"4.Quit\n";
cin>>choice;
switch(choice)
case 1:
cin>>item;
cin>>priority;
pq.insert(item, priority);
break;
case 2:
pq.del();
break;
case 3:
pq.display();
break;
case 4:
break;
default :
cout<<"Wrong choice\n";
while(choice != 4);
return 0;
OUTPUT:
RESULT:
PROGRAM 16:
Aim:
Algorithm:
Code:
#include<iostream>
class AVLtree
public:
int key;
AVLtree *left;
AVLtree *right;
int height;
};
if (tree == NULL)
return 0;
return tree->height;
tree->left = NULL;
tree->right =
NULL; tree->height
= 1; return(tree);
curr->left = t1;
t1->right = t2;
t1->height = max(getHeight(t1->left),
getHeight(t1->right)) + 1;
curr->height = max(getHeight(curr->left),
getHeight(curr->right)) + 1;
return curr;
curr->right =
t1->height = max(getHeight(t1->left),
getHeight(t1->right)) + 1;
curr->height = max(getHeight(curr->left),
getHeight(curr->right)) + 1;
return curr;
if (tree == NULL)
return 0;
if (tree == NULL)
return(newNode(key));
else
return tree;
tree->height = 1 + max(getHeight(tree->left),
getHeight(tree->right));
return rightRotate(tree);
return leftRotate(tree);
tree->left = leftRotate(tree->left);
return rightRotate(tree);
tree->right = rightRotate(tree->right);
return leftRotate(tree);
return tree;
}
if(root != NULL)
"; preOrder(root->left);
preOrder(root->right);
int main()
tree = insertNode(tree,
10); tree =
= insertNode(tree, 30);
tree = insertNode(tree,
40); tree =
= insertNode(tree, 25);
preOrder(tree);
return 0;}
OUTPUT:
RESULT:
PROGRAM 17:
Aim:
Algorithm:
Code:
#include <iostream>
#include <limits.h>
#define V 9
return min_index;
int dist[V];
bool sptSet[V];
dist[src] = 0;
sptSet[u] = true;
printSolution(dist);
int main()
int graph[V][V] = { { 0, 4, 0, 0, 0, 0, 0, 8, 0 },
{ 4, 0, 8, 0, 0, 0, 0, 11, 0 },
{ 0, 8, 0, 7, 0, 4, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 4, 14, 10, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
{ 8, 11, 0, 0, 0, 0, 1, 0, 7 },
{ 0, 0, 2, 0, 0, 0, 6, 7, 0 } };
dijkstra(graph, 0);
return 0;
}
OUTPUT:
RESULT: