SlideShare a Scribd company logo
Write a C program that reads the words the user types at the command prompt (using the 'int
argc, char * argv[] and store each unique letter in a Binary Search Tree. When a duplicate is
encountered do not store the letter again and instead keep track of the count in the tree. Once the
Binary Search tree has been created print out the tree both inorder and reverse order. Also print
the highest and lowest alphabetically letter in the tree if any.
Solution
# include
# include
# include
typedef struct BST {
int data;
struct BST *lchild, *rchild;
} node;
void insert(node *, node *);
void preorder(node *);
findMinimum(struct node* root)
findMaximum(struct node* root)
void reverseLevelOrder(struct node* root)
void main(int argc,char argv) {
char argv = 'N';
int key;
node *new_node, *root, *tmp, *parent;
node *get_node();
root = NULL;
clrscr();
printf(" Program For Binary Search Tree ");
do {
printf(" 1.Create");
printf(" 2.Search");
printf(" 3.Recursive Traversals");
printf(" 4.Exit");
printf(" Enter your choice :");
scanf("%d", &argc);
switch (argc) {
case 1:
do {
new_node = get_node();
printf(" Enter The Element ");
scanf("%d", &new_node->data);
if (root == NULL) /* Tree is not Created */
root = new_node;
else
insert(root, new_node);
printf(" Want To enter More Elements?(y/n)");
argv= getch();
} while (argv == 'y');
break;
case 2:
if (root == NULL)
printf("Tree Is Not Created");
else {
printf(" The Preorder display : ");
preorder(root);
}
break;
}
} while (argv != 4);
}
/*
Get new Node
*/
node *get_node() {
node *temp;
temp = (node *) malloc(sizeof(node));
temp->lchild = NULL;
temp->rchild = NULL;
return temp;
}
/*
This function is for creating a binary search tree
*/
void insert(node *root, node *new_node) {
if (new_node->data < root->data) {
if (root->lchild == NULL)
root->lchild = new_node;
return newNode(key);
else
insert(root->lchild, new_node);
}
if (new_node->data > root->data) {
if (root->rchild == NULL)
root->rchild = new_node;
return newNode(key);
else
insert(root->rchild, new_node);
}
}
if (key == node->key)
{
(node->count)++;
return node;
}
/*
This function displays the tree in preorder fashion
*/
void preorder(node *temp) {
if (temp != NULL) {
printf("%d", temp->data);
preorder(temp->lchild);
preorder(temp->rchild);
}
}
// Returns maximum value in a given Binary Tree
int findMaximum(struct node* root)
{
// Base case
if (root == NULL)
return INT_MAXIMUM;
// Return maximum of 3 values:
// 1) Root's data 2) Max in Left Subtree
// 3) Max in right subtree
int res = root->data;
int lres = findMaximum (root->lchild);
int rres = findMaximum (root->rchild);
if (lres > res)
res = lres;
if (rres > res)
res = rres;
return res;
}
// Returns minimum value in a given Binary Tree
int findMinimum(struct node* root)
{
// Base case
if (root == NULL)
return INT_MINIMUM;
// Return minimum of 3 values:
// 1) Root's data 2) Max in Left Subtree
// 3) Max in right subtree
int res = root->data;
int lres = findMinimum(root->lchild);
int rres = findMinimum(root->rchild);
if (lres < res)
res = lres;
if (rres < res)
res = rres;
return res;
}
void reverseLevelOrder(struct node* root)
{
int h = height(root);
int i;
for (i=h; i>=1; i--) //THE ONLY LINE DIFFERENT FROM NORMAL LEVEL ORDER
printGivenLevel(root, i);
}

More Related Content

Similar to Write a C program that reads the words the user types at the command.pdf

I have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdfI have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdf
fasttrackscardecors
 
Py spark cheat sheet by cheatsheetmaker.com
Py spark cheat sheet by cheatsheetmaker.comPy spark cheat sheet by cheatsheetmaker.com
Py spark cheat sheet by cheatsheetmaker.com
Lam Hoang
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
Add these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfAdd these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdf
indiaartz
 
Write a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docxWrite a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docx
noreendchesterton753
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
teyaj1
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdf
ajaycosmeticslg
 
Linked lists
Linked listsLinked lists
Linked lists
George Scott IV
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
JUSTSTYLISH3B2MOHALI
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
ajoy21
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
fathimafancyjeweller
 
In c++ format, for each function in the code, please using the comme.pdf
In c++ format, for each function in the code, please using the comme.pdfIn c++ format, for each function in the code, please using the comme.pdf
In c++ format, for each function in the code, please using the comme.pdf
rajkumarm401
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
anton291
 
#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx
ajoy21
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
deepua8
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
Programming Homework Help
 
Once you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxOnce you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docx
farrahkur54
 
Im having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdfIm having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdf
maheshkumar12354
 

Similar to Write a C program that reads the words the user types at the command.pdf (20)

I have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdfI have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdf
 
Py spark cheat sheet by cheatsheetmaker.com
Py spark cheat sheet by cheatsheetmaker.comPy spark cheat sheet by cheatsheetmaker.com
Py spark cheat sheet by cheatsheetmaker.com
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Add these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfAdd these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdf
 
Write a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docxWrite a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docx
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdf
 
Linked lists
Linked listsLinked lists
Linked lists
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
 
In c++ format, for each function in the code, please using the comme.pdf
In c++ format, for each function in the code, please using the comme.pdfIn c++ format, for each function in the code, please using the comme.pdf
In c++ format, for each function in the code, please using the comme.pdf
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
 
#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Once you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxOnce you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docx
 
Im having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdfIm having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdf
 

More from SANDEEPARIHANT

Do markets erode moral valuesDo markets erode moral values.pdf
Do markets erode moral valuesDo markets erode moral values.pdfDo markets erode moral valuesDo markets erode moral values.pdf
Do markets erode moral valuesDo markets erode moral values.pdf
SANDEEPARIHANT
 
Concept Simulation 25.2 illustrates the concepts pertinent to this pr.pdf
Concept Simulation 25.2 illustrates the concepts pertinent to this pr.pdfConcept Simulation 25.2 illustrates the concepts pertinent to this pr.pdf
Concept Simulation 25.2 illustrates the concepts pertinent to this pr.pdf
SANDEEPARIHANT
 
Based on what you have learned about the aquatic environment and the .pdf
Based on what you have learned about the aquatic environment and the .pdfBased on what you have learned about the aquatic environment and the .pdf
Based on what you have learned about the aquatic environment and the .pdf
SANDEEPARIHANT
 
A) If A, then B. If B, then C. Therefore, if A, then C There are 350.pdf
A) If A, then B. If B, then C. Therefore, if A, then C There are 350.pdfA) If A, then B. If B, then C. Therefore, if A, then C There are 350.pdf
A) If A, then B. If B, then C. Therefore, if A, then C There are 350.pdf
SANDEEPARIHANT
 
Describe the therapeutic goal in treating acid-peptic disease.So.pdf
Describe the therapeutic goal in treating acid-peptic disease.So.pdfDescribe the therapeutic goal in treating acid-peptic disease.So.pdf
Describe the therapeutic goal in treating acid-peptic disease.So.pdf
SANDEEPARIHANT
 
Compare structure and culture of two or more firms. Which would you .pdf
Compare structure and culture of two or more firms. Which would you .pdfCompare structure and culture of two or more firms. Which would you .pdf
Compare structure and culture of two or more firms. Which would you .pdf
SANDEEPARIHANT
 
WRITE A program that displays the values in the list numbers in desc.pdf
WRITE A program that displays the values in the list numbers in desc.pdfWRITE A program that displays the values in the list numbers in desc.pdf
WRITE A program that displays the values in the list numbers in desc.pdf
SANDEEPARIHANT
 
What is an oligopotent stem cell and what is an exampleSolution.pdf
What is an oligopotent stem cell and what is an exampleSolution.pdfWhat is an oligopotent stem cell and what is an exampleSolution.pdf
What is an oligopotent stem cell and what is an exampleSolution.pdf
SANDEEPARIHANT
 
What are 4 different types of CVI systemsSolutionThe four typ.pdf
What are 4 different types of CVI systemsSolutionThe four typ.pdfWhat are 4 different types of CVI systemsSolutionThe four typ.pdf
What are 4 different types of CVI systemsSolutionThe four typ.pdf
SANDEEPARIHANT
 
Why is RNA more prone than DNA to forming secondary structures.pdf
Why is RNA more prone than DNA to forming secondary structures.pdfWhy is RNA more prone than DNA to forming secondary structures.pdf
Why is RNA more prone than DNA to forming secondary structures.pdf
SANDEEPARIHANT
 
What are the advantages and disadvantage of using the metric system o.pdf
What are the advantages and disadvantage of using the metric system o.pdfWhat are the advantages and disadvantage of using the metric system o.pdf
What are the advantages and disadvantage of using the metric system o.pdf
SANDEEPARIHANT
 
Which of the following model organisms would be the best choice if y.pdf
Which of the following model organisms would be the best choice if y.pdfWhich of the following model organisms would be the best choice if y.pdf
Which of the following model organisms would be the best choice if y.pdf
SANDEEPARIHANT
 
What happens to jointly held stock between two siblings when one .pdf
What happens to jointly held stock between two siblings when one .pdfWhat happens to jointly held stock between two siblings when one .pdf
What happens to jointly held stock between two siblings when one .pdf
SANDEEPARIHANT
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
SANDEEPARIHANT
 
The HER incentive programs incentive payments to eligible hospitals, .pdf
The HER incentive programs incentive payments to eligible hospitals, .pdfThe HER incentive programs incentive payments to eligible hospitals, .pdf
The HER incentive programs incentive payments to eligible hospitals, .pdf
SANDEEPARIHANT
 
The comet Shoemaker-Levy 9 broke up into a number of pieces called t.pdf
The comet Shoemaker-Levy 9 broke up into a number of pieces called t.pdfThe comet Shoemaker-Levy 9 broke up into a number of pieces called t.pdf
The comet Shoemaker-Levy 9 broke up into a number of pieces called t.pdf
SANDEEPARIHANT
 
The existence of universal values is still a matter of debate. But e.pdf
The existence of universal values is still a matter of debate. But e.pdfThe existence of universal values is still a matter of debate. But e.pdf
The existence of universal values is still a matter of debate. But e.pdf
SANDEEPARIHANT
 
The c program will implement the Caesar Cipher. Your program shou.pdf
The c program will implement the Caesar Cipher. Your program shou.pdfThe c program will implement the Caesar Cipher. Your program shou.pdf
The c program will implement the Caesar Cipher. Your program shou.pdf
SANDEEPARIHANT
 
Amino acids are acids because they contain which functional group S.pdf
Amino acids are acids because they contain which functional group  S.pdfAmino acids are acids because they contain which functional group  S.pdf
Amino acids are acids because they contain which functional group S.pdf
SANDEEPARIHANT
 
Suppose that theta is an acute angle of a right triangle and tan (the.pdf
Suppose that theta is an acute angle of a right triangle and tan (the.pdfSuppose that theta is an acute angle of a right triangle and tan (the.pdf
Suppose that theta is an acute angle of a right triangle and tan (the.pdf
SANDEEPARIHANT
 

More from SANDEEPARIHANT (20)

Do markets erode moral valuesDo markets erode moral values.pdf
Do markets erode moral valuesDo markets erode moral values.pdfDo markets erode moral valuesDo markets erode moral values.pdf
Do markets erode moral valuesDo markets erode moral values.pdf
 
Concept Simulation 25.2 illustrates the concepts pertinent to this pr.pdf
Concept Simulation 25.2 illustrates the concepts pertinent to this pr.pdfConcept Simulation 25.2 illustrates the concepts pertinent to this pr.pdf
Concept Simulation 25.2 illustrates the concepts pertinent to this pr.pdf
 
Based on what you have learned about the aquatic environment and the .pdf
Based on what you have learned about the aquatic environment and the .pdfBased on what you have learned about the aquatic environment and the .pdf
Based on what you have learned about the aquatic environment and the .pdf
 
A) If A, then B. If B, then C. Therefore, if A, then C There are 350.pdf
A) If A, then B. If B, then C. Therefore, if A, then C There are 350.pdfA) If A, then B. If B, then C. Therefore, if A, then C There are 350.pdf
A) If A, then B. If B, then C. Therefore, if A, then C There are 350.pdf
 
Describe the therapeutic goal in treating acid-peptic disease.So.pdf
Describe the therapeutic goal in treating acid-peptic disease.So.pdfDescribe the therapeutic goal in treating acid-peptic disease.So.pdf
Describe the therapeutic goal in treating acid-peptic disease.So.pdf
 
Compare structure and culture of two or more firms. Which would you .pdf
Compare structure and culture of two or more firms. Which would you .pdfCompare structure and culture of two or more firms. Which would you .pdf
Compare structure and culture of two or more firms. Which would you .pdf
 
WRITE A program that displays the values in the list numbers in desc.pdf
WRITE A program that displays the values in the list numbers in desc.pdfWRITE A program that displays the values in the list numbers in desc.pdf
WRITE A program that displays the values in the list numbers in desc.pdf
 
What is an oligopotent stem cell and what is an exampleSolution.pdf
What is an oligopotent stem cell and what is an exampleSolution.pdfWhat is an oligopotent stem cell and what is an exampleSolution.pdf
What is an oligopotent stem cell and what is an exampleSolution.pdf
 
What are 4 different types of CVI systemsSolutionThe four typ.pdf
What are 4 different types of CVI systemsSolutionThe four typ.pdfWhat are 4 different types of CVI systemsSolutionThe four typ.pdf
What are 4 different types of CVI systemsSolutionThe four typ.pdf
 
Why is RNA more prone than DNA to forming secondary structures.pdf
Why is RNA more prone than DNA to forming secondary structures.pdfWhy is RNA more prone than DNA to forming secondary structures.pdf
Why is RNA more prone than DNA to forming secondary structures.pdf
 
What are the advantages and disadvantage of using the metric system o.pdf
What are the advantages and disadvantage of using the metric system o.pdfWhat are the advantages and disadvantage of using the metric system o.pdf
What are the advantages and disadvantage of using the metric system o.pdf
 
Which of the following model organisms would be the best choice if y.pdf
Which of the following model organisms would be the best choice if y.pdfWhich of the following model organisms would be the best choice if y.pdf
Which of the following model organisms would be the best choice if y.pdf
 
What happens to jointly held stock between two siblings when one .pdf
What happens to jointly held stock between two siblings when one .pdfWhat happens to jointly held stock between two siblings when one .pdf
What happens to jointly held stock between two siblings when one .pdf
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
 
The HER incentive programs incentive payments to eligible hospitals, .pdf
The HER incentive programs incentive payments to eligible hospitals, .pdfThe HER incentive programs incentive payments to eligible hospitals, .pdf
The HER incentive programs incentive payments to eligible hospitals, .pdf
 
The comet Shoemaker-Levy 9 broke up into a number of pieces called t.pdf
The comet Shoemaker-Levy 9 broke up into a number of pieces called t.pdfThe comet Shoemaker-Levy 9 broke up into a number of pieces called t.pdf
The comet Shoemaker-Levy 9 broke up into a number of pieces called t.pdf
 
The existence of universal values is still a matter of debate. But e.pdf
The existence of universal values is still a matter of debate. But e.pdfThe existence of universal values is still a matter of debate. But e.pdf
The existence of universal values is still a matter of debate. But e.pdf
 
The c program will implement the Caesar Cipher. Your program shou.pdf
The c program will implement the Caesar Cipher. Your program shou.pdfThe c program will implement the Caesar Cipher. Your program shou.pdf
The c program will implement the Caesar Cipher. Your program shou.pdf
 
Amino acids are acids because they contain which functional group S.pdf
Amino acids are acids because they contain which functional group  S.pdfAmino acids are acids because they contain which functional group  S.pdf
Amino acids are acids because they contain which functional group S.pdf
 
Suppose that theta is an acute angle of a right triangle and tan (the.pdf
Suppose that theta is an acute angle of a right triangle and tan (the.pdfSuppose that theta is an acute angle of a right triangle and tan (the.pdf
Suppose that theta is an acute angle of a right triangle and tan (the.pdf
 

Recently uploaded

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 

Write a C program that reads the words the user types at the command.pdf

  • 1. Write a C program that reads the words the user types at the command prompt (using the 'int argc, char * argv[] and store each unique letter in a Binary Search Tree. When a duplicate is encountered do not store the letter again and instead keep track of the count in the tree. Once the Binary Search tree has been created print out the tree both inorder and reverse order. Also print the highest and lowest alphabetically letter in the tree if any. Solution # include # include # include typedef struct BST { int data; struct BST *lchild, *rchild; } node; void insert(node *, node *); void preorder(node *); findMinimum(struct node* root) findMaximum(struct node* root) void reverseLevelOrder(struct node* root) void main(int argc,char argv) { char argv = 'N'; int key; node *new_node, *root, *tmp, *parent; node *get_node(); root = NULL; clrscr(); printf(" Program For Binary Search Tree "); do { printf(" 1.Create"); printf(" 2.Search"); printf(" 3.Recursive Traversals"); printf(" 4.Exit"); printf(" Enter your choice :"); scanf("%d", &argc);
  • 2. switch (argc) { case 1: do { new_node = get_node(); printf(" Enter The Element "); scanf("%d", &new_node->data); if (root == NULL) /* Tree is not Created */ root = new_node; else insert(root, new_node); printf(" Want To enter More Elements?(y/n)"); argv= getch(); } while (argv == 'y'); break; case 2: if (root == NULL) printf("Tree Is Not Created"); else { printf(" The Preorder display : "); preorder(root); } break; } } while (argv != 4); } /* Get new Node */ node *get_node() { node *temp; temp = (node *) malloc(sizeof(node)); temp->lchild = NULL; temp->rchild = NULL; return temp; }
  • 3. /* This function is for creating a binary search tree */ void insert(node *root, node *new_node) { if (new_node->data < root->data) { if (root->lchild == NULL) root->lchild = new_node; return newNode(key); else insert(root->lchild, new_node); } if (new_node->data > root->data) { if (root->rchild == NULL) root->rchild = new_node; return newNode(key); else insert(root->rchild, new_node); } } if (key == node->key) { (node->count)++; return node; } /* This function displays the tree in preorder fashion */ void preorder(node *temp) { if (temp != NULL) { printf("%d", temp->data); preorder(temp->lchild); preorder(temp->rchild); } } // Returns maximum value in a given Binary Tree int findMaximum(struct node* root)
  • 4. { // Base case if (root == NULL) return INT_MAXIMUM; // Return maximum of 3 values: // 1) Root's data 2) Max in Left Subtree // 3) Max in right subtree int res = root->data; int lres = findMaximum (root->lchild); int rres = findMaximum (root->rchild); if (lres > res) res = lres; if (rres > res) res = rres; return res; } // Returns minimum value in a given Binary Tree int findMinimum(struct node* root) { // Base case if (root == NULL) return INT_MINIMUM; // Return minimum of 3 values: // 1) Root's data 2) Max in Left Subtree // 3) Max in right subtree int res = root->data; int lres = findMinimum(root->lchild); int rres = findMinimum(root->rchild); if (lres < res) res = lres; if (rres < res) res = rres; return res; } void reverseLevelOrder(struct node* root) {
  • 5. int h = height(root); int i; for (i=h; i>=1; i--) //THE ONLY LINE DIFFERENT FROM NORMAL LEVEL ORDER printGivenLevel(root, i); }