Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#include<limits.h>
struct node
{
int id;
struct node *left,*right;
int contact;
char *name;
int dd,yy,mm;
};
int rr;
struct node *createNode(int id,int contact,int dd,int mm,int yy,char *name)
{
struct node * new = (struct node*)malloc(sizeof(struct node));
new->left = NULL;
new->right = NULL;
new->id = id;
new->contact = contact;
new->yy = yy;
new->mm = mm;
new->dd = dd;
//strcpy(new->name , name);
return new;
}
bool search(struct node *root,int id)
{
if (root == NULL)
{
return false;
}
else if (root->id == id)
{
return true;
}
else if (root->id >id)
{
return search(root->left,id);
}
else
return search(root->right,id);
}
struct node *insertNode(struct node *root,int id,int contact,int dd,int mm,int yy,char *name)
{
if (root == NULL)
{
struct node *new = createNode(id,contact,dd,mm,yy,name);
root = new;
return new;
}
else if (id <= root->id)
{
root->left = insertNode(root->left,id,contact,dd,mm,yy,name);
}
else
{
root->right = insertNode(root->right,id,contact,dd,mm,yy,name);
}
return root;
}
void range(struct node *root,int a,int b)
{
if (root == NULL)
{
return ;
}
if (root->id > a && root->id < b)
{
rr=rr+1;
}
range(root->left,a,b);
range(root->right,a,b);
}
struct node *findMin(struct node * root)
{
while(root->left != NULL)
root = root->left;
return root;
}
bool deadEnd(struct node* root, int min, int max)
{
if (!root)
return false;
if (min == max)
return true;
return deadEnd(root->left, min, root->id - 1) ||
deadEnd(root->right, root->id + 1, max);
}
int findMaxOfNumber(int a,int b)
{
if (a>b)
{
return a;
}
return b;
}
int findHeight(struct node *root)
{
int leftHeight;
int rightHeight;
if (root == NULL)
{
return 0;
}
leftHeight = findHeight(root->left);
rightHeight = findHeight(root->right);
return (findMaxOfNumber(leftHeight,rightHeight)+1);
}
void balanceFactor(struct node *root)
{
if (root == NULL)
{
return;
}
printf("the balane factor of %d ist%dn",root->id,findHeight(root->left)-findHeight(root->right));
balanceFactor(root->right);
balanceFactor(root->left);
}
int main()
{
int ch;
struct node *root = NULL;
int id1,dd1,mm1,yy1,no1,a,b;
char *name;
printf("enter 1 to insert 2 to calculate balance factor 3 to count the node in give range 4 to check wheather dead end s present or notn");
scanf("%d",&ch);
while(ch!=-1)
{
switch(ch)
{
case 1:
printf("enter id ,contact no, dob in dd/mm/yy and namen");
scanf("%d",&id1);
scanf("%d",&no1);
scanf("%d",&dd1);
scanf("%d",&mm1);
scanf("%d",&yy1);
scanf("%s",name);
root = insertNode(root,id1,no1,dd1,mm1,yy1,name);
break;
case 2:
balanceFactor(root);
break;
case 3:
//int a,b;
printf("enter the range of non");
scanf("%d",&a);
scanf("%d",&b);
range(root,a,b);
printf("range is %dn",rr );
break;
case 4:
if(deadEnd(root,findMin(root)->id,INT_MAX);)
printf("dead end foundn");
else
printf("not foundn");
break;
default:
printf("wrong choicen");
}
printf("enter 1 to insert 2 to calculate balance factor 3 to count the node in give range 4 to check wheather dead end s present or notn");
scanf("%d",&ch);
}
return 0;
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team