Code Monkey home page Code Monkey logo

basemax / swapbintreec Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 17 KB

A C program to swap the left and right nodes of a binary tree. It mean we are going to change the left node to right and right node to left. Even the child nodes of the left and right nodes will be swapped. This program is written in C language.

License: GNU General Public License v3.0

C 100.00%
bin-tree binary-tree binarytree bintree c data-structure datastructure tree swap-binary-tree swap-binarytree

swapbintreec's Introduction

Swap Bin-Tree in C

A C program to swap the left and right nodes of a binary tree. It mean we are going to change the left node to right and right node to left. Even the child nodes of the left and right nodes will be swapped. This program is written in C language.

Example

// Create the tree
struct Node *root = createNode(5);
root->left = createNode(3);
root->right = createNode(7);
root->left->left = createNode(2);
root->left->right = createNode(4);
root->right->left = createNode(6);
root->right->right = createNode(8);

// Print the tree
printf("Tree: ");
printTree(root);
printf("\n");

// Swap the nodes
root = swapNodes(root);

// Print the tree
printf("Swapped Tree: ");
printTree(root);
printf("\n");

OR

// Create the root node
struct Node *root = NULL;

// Insert nodes into the tree
root = insertNode(root, 5);
root = insertNode(root, 3);
root = insertNode(root, 2);
root = insertNode(root, 4);
root = insertNode(root, 7);
root = insertNode(root, 6);
root = insertNode(root, 8);

// Print the tree
printf("Tree: ");
printTree(root);
printf("\n");

// Swap the nodes
root = swapNodes(root);

// Print the tree
printf("Swapped Tree: ");
printTree(root);
printf("\n");

Copyright (c) 2023, Max Base

swapbintreec's People

Contributors

basemax avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.