fbpx

Struktur Data : Implementasi Binary Tree dalam Bahasa C

๐Ÿ“‹ Daftar Isi

Deklarasi Node

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

Fungsi Membuat Node Baru

struct node* newNode(int data)
{
  struct node* node = (struct node*)malloc(sizeof(struct node));
  node->data = data;
  node->left = NULL;
  node->right = NULL;

  return(node);
}

Source Code Lengkap

#include <stdio.h>

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

struct node* newNode(int data)
{
  struct node* node = (struct node*)malloc(sizeof(struct node));
  node->data = data;
  node->left = NULL;
  node->right = NULL;

  return(node);
}

int main()
{
  struct node *root = newNode(1);
  root->left = newNode(2);
  root->right = newNode =(3);
  root->left->right = newNode(4);

  return 0;
}

Materi Lengkap

Silakan baca juga beberapa artikel menarik kami tentang Tree (Bagian 1), daftar lengkapnya adalah sebagai berikut.


Tonton juga video pilihan dari kami berikut ini

Bagikan ke teman-teman Anda

Contact Us

How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site
error: Content is protected !!