generating k permutations of a series and then generating all possible binary trees from them
I am trying to solve a problem , (1) Take a positive integer (say K) as an input from the user. Generate all the K! Binary Search Tree from numbers {1,2,…,K}. i.e. all permutations and then I have to check For each K! BST, check whether that particular BST is full binary tree, complete binary tree and perfect binary tree. Can any one share the code in C or any programming language.What I generated is permutation of all the number of a given series in a file.
Code:
#include<string.h> |
What is the goal of this? Testing an existing binary-tree implementation?
|
Quote:
Honestly, I'm not sure how someone with the skill on display would be having trouble with either reading the file or creating the tree. You obviously know how to write files, so I assume you know how to read them. And each line is just a single integer, so there's no parsing involved other than atoi. A typical C binary search tree implementation would involve a Node struct containing data (the integer) and two pointers: one to each child. You then implement the standard algorithms for, say, the insert operation. There are zillions of examples online. |
That code opens, writes to, and closes the file n times. How ... inefficient.
@dugan, You're likely correct. I do wonder if the code was also part of the given part of the problem and therefore the question is then the actual assignment. Their most recent question was more clearly homework: https://www.linuxquestions.org/quest...em-4175636542/ @jamesbon, There is so very much information about B-tree's on the web. This is a very old programming concept. Please take the time to look a bit further on this subject. |
Quote:
|
Quote:
Code:
// accept empty lines |
All times are GMT -5. The time now is 09:29 PM. |