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

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...
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.
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?
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.
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)
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...
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Organizing and Presenting Data . Discuss the various types of graphs that are used to present...
Organizing and Presenting Data . Discuss the various types of graphs that are used to present data. Describe each of the graphs. Answer must be 250 words long!! No plagiarism!! Answer must be lengthy!!
**Java** - Creating from scratch. Original code hasn't been created yet. Design a class named Octagon...
**Java** - Creating from scratch. Original code hasn't been created yet. Design a class named Octagon that extends GeometricObject class and implements the Comparable and Cloneable interface. Assume that all eight sides of the octagon are of equal size. The area can be computed using following formula: Write a test program that creates an Octagon object with side values 5 and display its area and perimeter. Create a new object using clone method and compare the two objects using compareTo...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT