Question

In: Computer Science

You will be building 4 data structure types from scratch in C++ AND Java: -Undirected Graphs...

You will be building 4 data structure types from scratch in C++ AND Java:

-Undirected Graphs
-Directed Graphs
-Weighted Graph
-Binary Search Tree

Each of these data structures will have the following requirements:

-Undirected Graphs / Directed Graphs / Weighted Graph
-Methods:
-NumOfNodes
-NumOfEdges
-PrintNodes
-PrintEdges
-IsEqual
-AddNode
-AddEdge
-RemoveNode
-RemoveEdge
-Neighbors ( Adjacency List )
-BreadthFirstSearch
-DepthFirstSearch
-Binary Search Tree
-Methods:
-InOrderTraversal
-PostOrderTraversal
-PreOrderTraversal
-Search
-Insert
-RemoveNode
-DeleteTree
-FindMin
-FindMax
-IsEqual

Solutions

Expert Solution

Please give positive ratings for my effort. Kindly follow the comments for more. Thanks.

PROGRAM

#include <iostream>
using namespace std;

struct Node
{
   int data;
   struct Node* left, *right;
   Node(int data)
   {
       this->data = data;
       left = right = NULL;
   }
};

void printPostorder(struct Node* node)
{
   if (node == NULL)
       return;

   printPostorder(node->left);

   printPostorder(node->right);

   cout << node->data << " ";
}

void printInorder(struct Node* node)
{
   if (node == NULL)
       return;

   printInorder(node->left);

   cout << node->data << " ";

   printInorder(node->right);
}

void printPreorder(struct Node* node)
{
   if (node == NULL)
       return;

   cout << node->data << " ";

   printPreorder(node->left);

   printPreorder(node->right);
}

int main()
{
   struct Node *root = new Node(1);
   root->left = new Node(2);
   root->right   = new Node(3);
   root->left->left = new Node(4);
   root->left->right = new Node(5);

   cout << "\nPreorder traversal of binary tree is \n";
   printPreorder(root);

   cout << "\nInorder traversal of binary tree is \n";
   printInorder(root);

   cout << "\nPostorder traversal of binary tree is \n";
   printPostorder(root);

   return 0;
}

IMAGE OF PROGRAM

IMAGE OF OUTPUT


Related Solutions

In Java or C++, implement a stack and a queue using a linkedlist data structure.  You may...
In Java or C++, implement a stack and a queue using a linkedlist data structure.  You may not use any standard Java or C++ libraries. Assume your data structure only allows Strings. Implement the following operations for the data structure: Queue: enqueue, dequeue, create, isEmpty (10 points) Stack: push, pop, create, isEmpty (10 points) Here is a link to get started on transferring from Java to C++ http://www.horstmann.com/ccj2/ccjapp3.html (Links to an external site.) Upload a zip file with one implementation for...
1. Write a Java program from scratch that meets the following requirements: a. The program is...
1. Write a Java program from scratch that meets the following requirements: a. The program is in a file called Duplicates.java that defines a class called Duplicates (upper/lower case matters) b. The program includes a Java method called noDuplicates that takes an array of integers and returns true if all the integers in that array are distinct (i.e., no duplicates). Otherwise it returns false. Make sure the method is public static. example tests: noDuplicates({}) returns true noDuplicates({-1, 1}) returns true...
While designing the member of a steel structure building. Discuss the types of load that you...
While designing the member of a steel structure building. Discuss the types of load that you will consider in the design? Note:I need a lot of information on the question. Thank you.
C++ Create an ArrayBag template class from scratch. This will require you to create two files:...
C++ Create an ArrayBag template class from scratch. This will require you to create two files: ArrayBag.hpp for the interface and ArrayBag.cpp for the implementation. The ArrayBag class must contain the following protected members: static const int DEFAULT_CAPACITY = 200; // max size of items_ ItemType items_[DEFAULT_CAPACITY]; // items in the array bag int item_count_; // Current count of items in bag /** @param target to be found in items_ @return either the index target in the array items_ or...
Why are there different types of charts and graphs for different types of data (nominal, ordinal,...
Why are there different types of charts and graphs for different types of data (nominal, ordinal, scale?) Why do some charts use "frequencies" and others use real numbers? What is the difference?
Why are there different types of charts and graphs for different types of data (nominal, ordinal,...
Why are there different types of charts and graphs for different types of data (nominal, ordinal, scale?) Why do some charts use "frequencies" and others use real numbers? What is the difference?
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method...
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method that does the following: Prompt the user to enter a number of inches Read the number of inches entered from the console Convert the inches into an equivalent number of miles, yards, feet, and inches. Output the results to the console. For example, if a user entered 100000 inches, the program would output: 100000 inches is equivalent to: Miles: 1 Yards: 1017 Feet: 2...
Create a structure In C program named Student with the following components and appropriate data types:...
Create a structure In C program named Student with the following components and appropriate data types: Name, ID, CGPA i. Create an Array of Students of size three and take user input to fill the array. ii. Now find the student with the least CGPA and display his or hers Name, ID and CGPA.
You are expected to write a program from scratch. In the program, an array will be...
You are expected to write a program from scratch. In the program, an array will be initialized with 23 random integers between 1000 and 1999 (inclusive). The output of the program is 4 lines on the screen, specifically, All elements in the array (line 1) All elements in reverse order (line 2) Every element that is less than 1500 and also at an odd index (line 3) Every odd element that is larger than 1500 (line 4) Note that you...
in JAVA: implement a class called tree (from scratch) please be simple so i can understand...
in JAVA: implement a class called tree (from scratch) please be simple so i can understand thanks! tree(root) node(value, leftchild,rightchild) method: insert(value)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT