[ create a new paste ] login | about

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

C, pasted on Mar 25:
#include<stdio.h>
#include<stdlib.h>

struct node {
    int key;
    struct node *left;
    struct node *right;
};

typedef struct node mynode;

mynode* insert(mynode *root, int key)
{
    if(root == NULL) {
        root = (mynode*)malloc(sizeof(mynode));
        root->left = root->right = NULL;
        return root;
    }
    if(root->key < key) {
        root->right = insert(root->right, key);
    } else {
        root->left = insert(root->left, key);
    }
    return root;
}

void inorder(mynode *root)
{
    printf("\nInorder traversal is :\n\n");
    if(root != NULL) {
        root->left=inorder(root->left);
        printf("%d\t", root->key);
        root->right=inorder(root->right);
    }
    return root;
}

void preorder(mynode *root)
{
    printf("\nPreorder traversal is :\n\n");
    if(root != NULL) {
        printf("%d\t", root->key);
        root->left=preorder(root->left);
        root->right=preorder(root->right);
    }
    return root;
}

void postorder(mynode *root)
{
    printf("\nPostorder traversal is :\n\n");
    if(root != NULL) {
        root->left=postorder(root->left);
        root->right=postorder(root->right);
        printf("%d\t", root->key);
    }
    return root;
}

int main()
{
    mynode *root = NULL;
    printf("Sagar in BST program\n");
    root = insert(root,15);
    root = insert(root,11);
    root = insert(root,19);
    root = insert(root,2);
    root = insert(root,8);
    root = insert(root,13);
    root = insert(root,17);
    inorder(root);
    preorder(root);
    postorder(root);
    return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
In function 'inorder':
Line 31: error: void value not ignored as it ought to be
Line 33: error: void value not ignored as it ought to be
Line 35: warning: 'return' with a value, in function returning void
In function 'preorder':
Line 43: error: void value not ignored as it ought to be
Line 44: error: void value not ignored as it ought to be
Line 46: warning: 'return' with a value, in function returning void
In function 'postorder':
Line 53: error: void value not ignored as it ought to be
Line 54: error: void value not ignored as it ought to be
Line 57: warning: 'return' with a value, in function returning void


Create a new paste based on this one


Comments: