Abstract syntax tree implementation in C language?

1 answer

Answer

1219189

2026-04-23 23:00

+ Follow

This is a sample implementation of a binary tree which does inserting nodes, searching in the tree for a specific node and deleting the tree

#include

typedef struct bnode BinTree;

struct bnode {

char name[20];

int count;

BinTree *left;

BinTree *right;

};

BinTree* InsertBinTree ( BinTree*, char* );

BinTree* SearchBinTree ( BinTree*, char* );

BinTree* DeleteInBinTree ( BinTree*, char* );

void DisplayBinTree ( BinTree* );


int main ()

{

char ans, tmp, name[20];

BinTree *root = NULL;

printf ("\nInserting nodes...\n");

do {

printf ("Type the name of the node to insert: ");

scanf ("c", name, &tmp);

root = InsertBinTree(root, name);

printf ("Another one (Y/N)? ");

scanf("c", &ans, &tmp);

} while (ans NULL )

return NULL;

while ( root->left != NULL )

root = root->left;

return root;

}

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.