Professional Documents
Culture Documents
Data Structur Program
Data Structur Program
if(head->next == head) {
head = NULL; Binary search tree
return tempLink;
} #include <stdio.h>
#include <stdlib.h>
//mark next to first link as first
head = head->next; struct node
{
//return the deleted link int data; //node will store an integer
return tempLink; struct node *right_child; // right child
} struct node *left_child; // left child
};
//display the list
void printList() { struct node* search(struct node *root, int x)
{
struct node *ptr = head; if(root==NULL || root->data==x) //if root-
printf("\n[ "); >data is x then the element is found
return root;
//start from the beginning else if(x>root->data) // x is greater, so we will
if(head != NULL) { search the right subtree
return search(root->right_child, x);
while(ptr->next != ptr) { else //x is smaller than the data, so we will
printf("(%d,%d) ",ptr->key,ptr->data); search the left subtree
ptr = ptr->next; return search(root->left_child,x);
} }
}
//function to find the minimum value in a node
printf(" ]"); struct node* find_minimum(struct node *root)
} {
if(root == NULL)
void main() { return NULL;
insertFirst(1,10); else if(root->left_child != NULL) // node with
insertFirst(2,20); minimum value will have no left child
insertFirst(3,30); return find_minimum(root->left_child); //
insertFirst(4,1); left most element will be minimum
insertFirst(5,40); return root;
insertFirst(6,56); }