Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct treeNode {
struct treeNode* leftPtr;
int data;
struct treeNode* rightPtr;
};

typedef struct treeNode TreeNode;
typedef TreeNode* TreeNodePtr;

void insertNode(TreeNodePtr* treePtr, int value);
void inOrder(TreeNodePtr treePtr);
void preOrder(TreeNodePtr treePtr);
void postOrder(TreeNodePtr treePtr);

int main(void) {
TreeNodePtr rootPtr = NULL;

srand(time(NULL));
puts("The numbers being placed in the tree are:");

for (unsigned int i = 1; i <= 10; ++i) {
int item = rand() % 15;
printf("%3d", item);
insertNode(&rootPtr, item);
}

puts("\n\nThe preOrder traversal is: ");
preOrder(rootPtr);

puts("\n\nThe inOrder traversal is: ");
inOrder(rootPtr);

puts("\n\nThe postOrder traversal is: ");
postOrder(rootPtr);
}

void insertNode(TreeNodePtr* treePtr, int value) {
if (*treePtr == NULL) {
*treePtr = malloc(sizeof(TreeNode));

if (*treePtr != NULL) {
(*treePtr)->data = value;
(*treePtr)->leftPtr = NULL;
(*treePtr)->rightPtr = NULL;
}
else {
printf("%d not inserted. No memory available.\n", value);
}
}
else {

if (value < (*treePtr)->data) {
insertNode(&((*treePtr)->leftPtr), value);
}

else if (value > (*treePtr)->data) {
insertNode(&((*treePtr)->rightPtr), value);
}
else {
printf("%s", " dup");
}
}
}

void inOrder(TreeNodePtr treePtr)
{
if (treePtr != NULL) {
inOrder(treePtr->leftPtr);
printf("%3d", treePtr->data);
inOrder(treePtr->rightPtr);
}
}

void preOrder(TreeNodePtr treePtr)
{
if (treePtr != NULL) {
printf("%3d", treePtr->data);
preOrder(treePtr->leftPtr);
preOrder(treePtr->rightPtr);
}
}

void postOrder(TreeNodePtr treePtr)
{
if (treePtr != NULL) {
postOrder(treePtr->leftPtr);
postOrder(treePtr->rightPtr);
printf("%3d", treePtr->data);
}
}

I'm confused on what the problem is with my code. Specifically *treePtr = malloc(sizeof(TreeNode));

It says '=' cannot convert from void to treeNodePtr. This is C Programming

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education