SlideShare a Scribd company logo
1 of 1
#include <stdio.h> #include <Stdlib.h> #include <stdbool.h> enum {
FILE_OPEN_ERROR, MEMORY_ALLOCATION_ERROR }; #define NAME(a) #a #define
CATCH(ERROR) do{printf(NAME(ERROR));exit(0);}while(false) #define
CALLOC(type,data_num,ptr)
do{if(!(ptr=(type*)calloc(data_num,sizeof(type)))){CATCH(MEMORY_ALLOCATION_
ERROR);}}while(false) typedef struct node* link; typedef struct node { link
l_ch; int key; link r_ch; } node; link root; #define MAX_SIZE 500 #define
RAND (rand() % MAX_SIZE + 1) int n, seed; link modified_search(int key);
bool add_node(int key); void make_BST(void); void search(int key); void
inorder(link ptr); int main(void) { printf("random number generation (1 ~
%d)n", MAX_SIZE); printf("%s", "the number of nodes in BST (less than and
equal to 50) : "); scanf_s("%d", &n); printf("%s", "seed : ");
scanf_s("%u", &seed); printf("ncreating a BST from random numbersn");
srand(seed); make_BST(); int find_key; printf("Enter the key to search >>
"); scanf_s("%d", &find_key); search(find_key); printf("Inorder treversal
of the BST shows the sorted sequencen"); inorder(root); printf("n");
return 0; } link modified_search(int key) { link location_of_parent = NULL;
if (!root) return NULL; else { for (location_of_parent =
root;location_of_parent;) { if (location_of_parent->key < key) { if
(!location_of_parent->r_ch) return location_of_parent; else
location_of_parent = location_of_parent->r_ch; } else if
(location_of_parent->key == key) return NULL; else { if
(!location_of_parent->l_ch) return location_of_parent; else
location_of_parent = location_of_parent->l_ch; } } } return
location_of_parent; } bool add_node(int key) { link tmp; CALLOC(node, 1,
tmp); tmp->key = key; if (!root) root = tmp; else { link location_of_parent
= modified_search(key); if (!location_of_parent) return false; if
(location_of_parent->key < key) location_of_parent->r_ch = tmp; else
location_of_parent->l_ch = tmp; } return true; } void make_BST(void) {
printf("< Make BST >n"); int i; int tmp; printf("generating numbers : ");
for (i = 0;i < n;) { tmp = RAND; if (add_node(tmp)) { printf("%4d", tmp);
i++; } } printf("n"); } void search(int key) { printf("The search process
: "); link scaf; bool is_find = false; for (scaf = root;scaf;) { printf("%d
=> ", scaf->key); if (scaf->key == key) { is_find = true; break; } scaf =
(scaf->key < key) ? (scaf->r_ch) : (scaf->l_ch); } printf("n"); if
(is_find) printf("The element is in BSTn"); else printf("The element is
not in BSTn"); } void inorder(link ptr) { if (ptr) { inorder(ptr->l_ch);
printf("%4d", ptr->key); inorder(ptr->r_ch); } }

More Related Content

Similar to include.docx

Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlHideaki Ohno
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)Ankit Gupta
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)hasan0812
 
Потоки в перле изнутри
Потоки в перле изнутриПотоки в перле изнутри
Потоки в перле изнутриIlya Zelenchuk
 
R57shell
R57shellR57shell
R57shellady36
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptxSanthiya S
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxgordienaysmythe
 
Aodv routing protocol code in ns2
Aodv routing protocol code in ns2Aodv routing protocol code in ns2
Aodv routing protocol code in ns2Prof Ansari
 
C basics
C basicsC basics
C basicsMSc CST
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 
package com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdfpackage com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdfaparnacollection
 
Effective C#
Effective C#Effective C#
Effective C#lantoli
 
7segment scetch
7segment scetch7segment scetch
7segment scetchBang Igo
 

Similar to include.docx (20)

Data structures
Data structuresData structures
Data structures
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
Потоки в перле изнутри
Потоки в перле изнутриПотоки в перле изнутри
Потоки в перле изнутри
 
R57shell
R57shellR57shell
R57shell
 
Shell.php
Shell.phpShell.php
Shell.php
 
Vcs28
Vcs28Vcs28
Vcs28
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 
Aodv routing protocol code in ns2
Aodv routing protocol code in ns2Aodv routing protocol code in ns2
Aodv routing protocol code in ns2
 
C basics
C basicsC basics
C basics
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
package com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdfpackage com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdf
 
Effective C#
Effective C#Effective C#
Effective C#
 
7segment scetch
7segment scetch7segment scetch
7segment scetch
 

Recently uploaded

Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 

Recently uploaded (20)

Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 

include.docx

  • 1. #include <stdio.h> #include <Stdlib.h> #include <stdbool.h> enum { FILE_OPEN_ERROR, MEMORY_ALLOCATION_ERROR }; #define NAME(a) #a #define CATCH(ERROR) do{printf(NAME(ERROR));exit(0);}while(false) #define CALLOC(type,data_num,ptr) do{if(!(ptr=(type*)calloc(data_num,sizeof(type)))){CATCH(MEMORY_ALLOCATION_ ERROR);}}while(false) typedef struct node* link; typedef struct node { link l_ch; int key; link r_ch; } node; link root; #define MAX_SIZE 500 #define RAND (rand() % MAX_SIZE + 1) int n, seed; link modified_search(int key); bool add_node(int key); void make_BST(void); void search(int key); void inorder(link ptr); int main(void) { printf("random number generation (1 ~ %d)n", MAX_SIZE); printf("%s", "the number of nodes in BST (less than and equal to 50) : "); scanf_s("%d", &n); printf("%s", "seed : "); scanf_s("%u", &seed); printf("ncreating a BST from random numbersn"); srand(seed); make_BST(); int find_key; printf("Enter the key to search >> "); scanf_s("%d", &find_key); search(find_key); printf("Inorder treversal of the BST shows the sorted sequencen"); inorder(root); printf("n"); return 0; } link modified_search(int key) { link location_of_parent = NULL; if (!root) return NULL; else { for (location_of_parent = root;location_of_parent;) { if (location_of_parent->key < key) { if (!location_of_parent->r_ch) return location_of_parent; else location_of_parent = location_of_parent->r_ch; } else if (location_of_parent->key == key) return NULL; else { if (!location_of_parent->l_ch) return location_of_parent; else location_of_parent = location_of_parent->l_ch; } } } return location_of_parent; } bool add_node(int key) { link tmp; CALLOC(node, 1, tmp); tmp->key = key; if (!root) root = tmp; else { link location_of_parent = modified_search(key); if (!location_of_parent) return false; if (location_of_parent->key < key) location_of_parent->r_ch = tmp; else location_of_parent->l_ch = tmp; } return true; } void make_BST(void) { printf("< Make BST >n"); int i; int tmp; printf("generating numbers : "); for (i = 0;i < n;) { tmp = RAND; if (add_node(tmp)) { printf("%4d", tmp); i++; } } printf("n"); } void search(int key) { printf("The search process : "); link scaf; bool is_find = false; for (scaf = root;scaf;) { printf("%d => ", scaf->key); if (scaf->key == key) { is_find = true; break; } scaf = (scaf->key < key) ? (scaf->r_ch) : (scaf->l_ch); } printf("n"); if (is_find) printf("The element is in BSTn"); else printf("The element is not in BSTn"); } void inorder(link ptr) { if (ptr) { inorder(ptr->l_ch); printf("%4d", ptr->key); inorder(ptr->r_ch); } }