Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to implement a binary search tree in C using these methods: /** Create a proper, empty binary search tree object. * * Pre:

I need to implement a binary search tree in C using these methods:

/** Create a proper, empty binary search tree object. * * Pre: compare is the name of a user-defined function satisfying the BST specification * display is the name of a user-defined function satisfying the BST specification * destroy is the name of a user-defined function satisfying the BST specification * * Returns: a BST object with NULL root and configured to use the three user-supplied * functions for comparing, destroying and displaying user-defined data objects * stored in the tree */ BST BST_create(int32_t (*compare)(const BSTNode* const left, const BSTNode* const right), void (*display)(FILE* fp, const BSTNode* const pD), void (*destroy)(BSTNode* pNode));

/** Inserts user data object into a BST, unless it duplicates an existing object. * * Pre: pTree points to a proper BST object * userNode points to a proper BSTNode object * * Returns: true iff the insertion was performed; the implementation will not * insert a new element that is equal to one that's already in the * BST (according to the user-supplied comparison function) */ bool BST_insert(BST* const pTree, const BSTNode* const userNode);

/** Searches a proper BST for an occurence of a user data object that equals * *pData (according to the user-supplied comparison function). * * Pre: pTree points to a proper BST object * pData points to a proper BSTNode object * * Returns: pointer to matching user data object; NULL if no match is found */ BSTNode* BST_find(const BST* const pTree, const BSTNode* const userNode);

/** Deallocates all dynamic memory associated with a proper BST object. * * Pre: *pTree is a proper BST object * Post: all the user payloads and payload wrappers associated with *pTree * have been freed * the BST object itself is NOT freed since it may or may not have * been allocated dynamically; that's the responsibility of the caller * * Calls: Payload_destroy() to handle destruction of the user's data object */ void BST_destroy(BST* const pTree);

Structs used:

struct _PayloadWrapper { Payload* userdata; // pointer to a user data object BSTNode node; }; typedef struct _PayloadWrapper PayloadWrapper;

struct _Payload { char* str; }; typedef struct _Payload Payload;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

Define overfitting.

Answered: 1 week ago

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago

Question

3. What are potential solutions?

Answered: 1 week ago

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago