[ create a new paste ] login | about

Link: http://codepad.org/AWoxUgkv    [ raw code | output | fork ]

C, pasted on Jan 11:
#include <stdio.h>
#include <stdlib.h>
struct n {
	int info;
	struct n *right;
	struct n *left;
};
typedef struct n *node;
int min, max;
node elemanEkle(node root, int x) {
	if (root == NULL) {
		node root = (node)malloc(sizeof(struct n));
		root->info = x;
		root->left = NULL;
		root->right = NULL;
		return root;
	}
	if (root->info < x) {
		root->right = elemanEkle(root->right, x);
		return root;
	}
	if (root->info > x) {
		root->left = elemanEkle(root->left, x);
		return root;
	}
}
void listele(node root) {
	if (root == NULL)
		return;
	printf(" %d - ", root->info);
	listele(root->left);
	listele(root->right);
}
void minDeger(node root) {
	while (root->left != NULL)
		root = root->left;

		min = root->info;
	
	printf("MIN DEGER: %d ", min);
}
int main() {
	node root = NULL;
	root = elemanEkle(root, 20);
	root = elemanEkle(root, 15);
	root = elemanEkle(root, 25);
	root = elemanEkle(root, 22);
	root = elemanEkle(root, 35);
	root = elemanEkle(root, 19);
	root = elemanEkle(root, 10);
	root = elemanEkle(root, 5);
	root = elemanEkle(root, 8);
	root = elemanEkle(root, 2);
	
	listele(root);
	printf("\n");
	minDeger(root);
}


Output:
1
2
 20 -  15 -  10 -  5 -  2 -  8 -  19 -  25 -  22 -  35 - 
MIN DEGER: 2 


Create a new paste based on this one


Comments: