January 17th, 2016, 04:22 PM
C: Enumeration in a struct
Define enumeration E with labels folder and file.
Define struct folder that represents node of a tree with fields:
name, (E)identifier, and left-right child.
Define struct file which represents node of a tree without children and has fields:
Store a folder in a tree by folder name.
Display the read data of a tree.
Is this correct declaration of an enumeration and structs:
How to store this data structure to binary tree?
typedef struct node
struct node *left,*right;
January 17th, 2016, 06:54 PM
I named the file indicated by your code as e.c and then compiled with gcc via make to an object
cc -Wall -g -c -o e.o e.c
and there were no errors! You could have done that. The start of your program looks ok.
As to storing it in a binary tree you ought to choose some feature to order the tree. Otherwise were you to, for instance, just stick everything on the right you'd have nothing more than a memory hungry linked list. Gosh, what happens if you load a binary tree with a pre-sorted list? Well, it's better in some ways perhaps than a random singly linked list. If you want extra credit implement a balanced binary tree, for instance the red-black tree.
Pattern matching - Rosetta Code
The j entry, which I wrote, has a reference.
Last edited by b49P23TIvg; January 17th, 2016 at 06:57 PM.
[/code] are essential for python code and Makefiles!
April 19th, 2017, 09:18 AM
An enum and a struct are totally different concepts, fulfilling different purposes.
An enum lets you declare a series of identifiers for use in your code. The compiler replaces them with numbers for you. It's often useful for making your code more readable and maintainable, because you can use descriptive names without the performance penalty of string comparisons. It can also make the code less bug-prone because you don't have to keep writing in specific numbers everywhere, which could go wrong if a number changes.
A struct is a data structure. At its simplest, it contains zero or more pieces of data (variables or objects), grouped together so they can be stored, processed, or passed as a single unit. You can usually have multiple copies (or instances) of it. A struct can be a lot more complex though. It's actually exactly the same as a class, except that members are public by default instead of private. Like a class, a struct can have member functions and template parameters and so on.
One of the vital difference between structs and enums is that an enum doesn't exist at run-time. It's only for your benefit when you're read/writing the code. However, instances of structs (and classes) certainly can exist in memory at runtime.
From a coding standpoint, each identifier in an enum doesn't have its own type. Every member within a struct must have a type.
Learn C++ here https://hackr.io/tutorials/learn-c-c-plus-plus