Here a CPP code to make a BST and perform its all operations.
Programming Talks
Programming , Project , Tutorials
Tuesday, 24 February 2015
C++ program for creation and traversal of a Binary Tree
A Simple CPP program for creation a binary tree and understand traversal of that tree.
#include<iostream.h> #include<conio.h> #include<process.h> struct tree_node { tree_node *left; tree_node *right; int data; } ; class bst { tree_node *root; public: bst() { root=NULL; } int isempty() { return(root==NULL); } void insert(int item); void inordertrav(); void inorder(tree_node *); void postordertrav(); void postorder(tree_node *); void preordertrav(); void preorder(tree_node *); }; void bst::insert(int item) { tree_node *p=new tree_node; tree_node *parent; p->data=item; p->left=NULL; p->right=NULL; parent=NULL; if(isempty()) root=p; else { tree_node *ptr; ptr=root; while(ptr!=NULL) { parent=ptr; if(item>ptr->data) ptr=ptr->right; else ptr=ptr->left; } if(item<parent->data) parent->left=p; else parent->right=p; } } void bst::inordertrav() { inorder(root); } void bst::inorder(tree_node *ptr) { if(ptr!=NULL) { inorder(ptr->left); cout<<" "<<ptr->data<<" "; inorder(ptr->right); } } void bst::postordertrav() { postorder(root); } void bst::postorder(tree_node *ptr) { if(ptr!=NULL) { postorder(ptr->left); postorder(ptr->right); cout<<" "<<ptr->data<<" "; } } void bst::preordertrav() { preorder(root); } void bst::preorder(tree_node *ptr) { if(ptr!=NULL) { cout<<" "<<ptr->data<<" "; preorder(ptr->left); preorder(ptr->right); } } void main() { bst b; b.insert(52); b.insert(25); b.insert(50); b.insert(15); b.insert(40); b.insert(45); b.insert(20); cout<<"inorder"<<endl; b.inordertrav(); cout<<endl<<"postorder"<<endl; b.postordertrav(); cout<<endl<<"preorder"<<endl; b.preordertrav(); getch(); } |
CPP Project LIC Database system
If you want to go the customer section then you have to select its option and if you want to be logged in as agent of LIC Database system then you have been provided with other option. These options are entered at the current cursor position and after which its screen will be appear, where they will required to enter their id to use their particular account. Existing customers will able to check their policy details under which they have made investment.
Existing System
Existing LIC Database system do not provide facility to select the particular policy by going through each policy details. Customers has to be dependent on agent to get details on particular policy. While taking any particular policy, customers do not able to get information what will be the minimum installment to be made and in what mode. Agent are also not able to check their account any time as per their requirement and the details of customers who have taken policy from them along with their policy maturity date. The present system do not provide the correct medium for the agents to know their commissions which has been made while selling any particular policy. Also the present system do not uses the concept of OOP’S by which changes can be made easily to any particular section within the program code easily.
Proposed System
The current system stored all data in particular file in the binary format which is not able to read by others. Its command prompt will not able its users to know about the background details thus providing the feature of extra security and reliability. Customers will have the option to review any policy as per their choice and select particular policy if they like it. Each customers and agent will have unique id by which they will able to check their account at any time.
Download Project
LIC Database system Abstract | Download Abstract |
LIC Database system Source Code | Download Source Code |
Tuesday, 2 April 2013
Queue using Array in C++
What Is Queue ???
A queue is an ordered list in which all insertions take place at one end, the rear, while all deletions take place at the other end, the front. All Queue Operation like insertion , deletion or display as elements can understand by following Program.
Source Code :
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#define max 6
int q[10],rear=-1,front=-1;
void insertInQ(int data)
{
if(rear==-1&&front==-1)
{
rear=0;
front=0;
q[rear]=data;
return;
}
if(front==0&&rear==max-1||front==rear+1)
{
cout<<"overflow";
return;
}
if(rear==max-1)
rear=0;
else
rear=rear+1;
q[rear]=data;
}
int deleteFromQ(){
int data;
if(front==-1&&rear==-1)
{
cout<<"underflow";
return 0;
}
data=q[front];
q[front]=NULL;
if(front==rear)
{
front=rear=-1;
}
else
{
if(front==max-1)
front=0;
else
front=front+1;
}
return data;
}
void printQ()
{
int i;
for(i=0;i<max;i++)
{
if(q[i]==NULL)
cout<<"t";
else
cout<<"t"<<q[i];
}
}
int main()
{
int ch,d;
while(1)
{
cout<<"n=========queue operations===========n 1.insert n 2.delete n 3.show n 4.exit n ========================= n Enter your choice : " ;
cin>>ch;
switch(ch)
{
case 1 :
cout<<"n enter data :" ;
cin>>d;
insertInQ(d);
break;
case 2:
d=deleteFromQ();
cout<<"n data is :"<<d;
break;
case 3:
printQ();
break;
case 4:
exit(0);
default :
cout<<"n wrong choice------ n";
break;
}
}
getch();
return 0;
}
|
Output :
Subscribe to:
Posts (Atom)