answersLogoWhite

0


Best Answer

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;

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Abstract syntax tree implementation in C language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Computer Science

What is the purpose of declaring abstract method?

Abstract Class: The class which contains the common features of components of several classes, but cannot it be instantiated by itself. It represents an abstract concept for which there is no actual existing expression. For instance, "Vegetation" is an abstract class - there is no such real, real thing as generic vegetation. Instead, there are only instances of vegetation, such as mango tree and rose plant, which are types of vegetation, and share common characteristics, such as having leaves and stem in at least part of the lifecycle. SO in software engineering, an abstract class is a class in a nominative type system which is declared by the programmer, and which has the property that it contains members which are also members of some declared subtype. In many object oriented programming languages, abstract classes are known as abstract base classes, interfaces, traits, mixins, flavors, or roles. Note that these names refer to different language constructs which are (or may be) used to implement abstract types. We can also say that abstract class is : -- A class which is used only as an ancestor and is never instantiated. In other word a concrete definition will say that A type of class with pure virtual member functions and one or more methods that are declared but not implemented, that behaves as a base class but prohibits the instantiation of any members of that class. i.e. It has a complete interface but only a partial implementation It is used to take advantage of inheritance yet prohibiting the generation of objects that are not completely defined. Concrete subclasses of an abstract class are required to flesh out the implementation by overriding the abstract methods.


What is the tree reasons is computer important college students?

Spelling and grammar check, and online language translation would certainly be three examples.....


How many types of binary tree?

A binary tree is type of tree with finite number of elements and is divided into three main parts. the first part is called root of the tree and itself binary tree which exists towards left and right of the tree. There are a no. of binary trees and these are as follows : 1) rooted binary tree 2) full binary tree 3) perfect binary tree 4) complete binary tree 5) balanced binary tree 6) rooted complete binary tree


What does root mean in computer language?

In computer language, 'root' refers to the highest level of administrative access within a system or network, permitting full control over all files, directories, and functions. In coding, 'root' often denotes the base or starting point in a directory or data structure like a tree or graph.


What tree does a conker come from?

a horsechestnut tree

Related questions

What is syntax in computing?

If in the market research context, Syntax is normally the set of commands written while using database softwares like SPSS, Quantum Etc to generate tables In computer science, especially in the subfield of programming languages, the syntax of a computer language is the set of allowed reserved words and possible token order in a program. The syntax of a programming language is the set of rules that a sequence of characters in a source code file must follow to be considered a conforming program in that language. The rules specify how the character sequences are to be chunked into tokens (the lexical grammar), the permissible sequences of these tokens and some of the meaning to be attributed to these permissible token sequences (additional meaning is assigned by the semantics of the language). The syntactic analysis of source code usually entails the transformation of the linear sequence of tokens into a hierarchical syntax tree (abstract syntax trees are one convenient form of syntax tree). This process is called parsing, as it is in syntactic analysis in linguistics. Tools have been written that automatically generate parsers from a specification of a language grammar written in Backus-Naur form, e.g., Yacc (yet another compiler compiler). The syntax of computer languages is often at level-2 (ie, a context-free grammar) in the Chomsky hierarchy. As such the possible ordering of tokens is usually very restricted. The analysis of a program's syntax is usually performed using an automatically generated program known as a parser which often builds an abstract syntax tree.


How do you build a programming language?

This is a very large topic indeed and I fully recommend the book "Compilers: Principles, Techniques, and Tools" by Aho, Sethi, and Ullman. But the general process first involves first defining regular expressions that will be used to break up an input program into a series of tokens. The part of the compiler/interpreter that performs this function is called a scanner. From there a parser should be created based on the context free grammar of the language. Parsing produces a representation of the input program in memory called an abstract syntax tree. From that point a compiler can be created by generating assembly language for the program. Or an interpreter can be created by executing the abstract syntax tree directly.


What is a tree set?

A TreeSet is simply an implementation of the AbstractSet abstract class using a TreeMap to back the data. This is an ordered Set implementation with log(n) time cost to access or modify the data.


Difference between syntax tree and parse tree?

i dont know but i


What is tree abstract data type?

It is my opinion that you're just looking at a tree structure for data; calling it asbstract just means you're not looking at a concrete implementation - rather the idea of tree data structuring. There are a couple of links below to get you started http://en.wikipedia.org/wiki/Tree_(computer_science) http://www.sqa.org.uk/e-learning/LinkedDS04CD/index.htm WRT it being a data type, it depends on the language. Some have Tree Types in the language, C# for example, some require you to build your own. I hope this helps - if not I'm sure someone much wiser than I will come along...


Implementation of general tree?

Binary tree is a tree where each node has one or two children.While in case of general tree, a node can have more than two children.A binary tree can be empty, whereas the general tree cannot be empty


Difference between parse tree and syntax tree?

Parse trees (also known as Concrete Syntax Trees) contain every token of the input as a leaf, and the interior nodes are nonterminals in the grammar used to parse. Abstract Syntax Trees omit much of the detail that would be present in a CST. There are still leaf nodes when the associated tokens are information-bearing (such as identifiers and literals), but, for example, keywords and punctuation are not present in an AST. The interior nodes represent language constructs as defined by the grammar. An AST for an "if" statement (for example) would consist of one node to represent the "if" construct, and two or three subtrees, one for the "if" condition and another one or two for the "the" and optional "else" parts. The CST for such a construct would also contain the "if"/"then"/"else" keywords, such that you could walk the tree to obtain the original token sequence.


What is Parse tree?

A syntax tree is a tree representation of the syntactic structure of the source code where the node denotes a construct. For more information, visit the link below:


Which directory implementation is mostly used in operating system?

Tree directory structure


How do you say tree in abaluya language?

The English word 'tree', is said in Abaluhya (Luhya) language as "omusala".


What is the purpose of declaring abstract method?

Abstract Class: The class which contains the common features of components of several classes, but cannot it be instantiated by itself. It represents an abstract concept for which there is no actual existing expression. For instance, "Vegetation" is an abstract class - there is no such real, real thing as generic vegetation. Instead, there are only instances of vegetation, such as mango tree and rose plant, which are types of vegetation, and share common characteristics, such as having leaves and stem in at least part of the lifecycle. SO in software engineering, an abstract class is a class in a nominative type system which is declared by the programmer, and which has the property that it contains members which are also members of some declared subtype. In many object oriented programming languages, abstract classes are known as abstract base classes, interfaces, traits, mixins, flavors, or roles. Note that these names refer to different language constructs which are (or may be) used to implement abstract types. We can also say that abstract class is : -- A class which is used only as an ancestor and is never instantiated. In other word a concrete definition will say that A type of class with pure virtual member functions and one or more methods that are declared but not implemented, that behaves as a base class but prohibits the instantiation of any members of that class. i.e. It has a complete interface but only a partial implementation It is used to take advantage of inheritance yet prohibiting the generation of objects that are not completely defined. Concrete subclasses of an abstract class are required to flesh out the implementation by overriding the abstract methods.


Which can be used to represent a many to many relation with abstract data types?

tree