Files in C
C supports two types of files:
-
character files (streams)
-
binary files
Operations on files:
FILE* fopen (char * name, char mode)
void fclose (FILE* file)
size_t fread (void* b, size_t s, size_t n, FILE* f)
size_t fwrite (void* b, size_t s, size_t n, FILE* f)
int fseek (FILE* f, long offset, int base)
base can be:
SEEK_SET - from the beginning
SEEK_CUR - from current position
SEEK_END - from the end
int feof (FILE* f)
2-3 Trees
Definition. 2-3 tree:
q a node contains one or two keys
q every internal node contains two or three children
q the leaves are all at the same level in the tree
q the tree has the search property:
-
nodes in the left subtree < value of the first key
-
nodes in the middle subtree >= value of the first key
-
node in the right subtree >= value of the second key (if there is any)
structure TTNode{
int nkeys;
KEY lkey;
KEY rkey;
TTNode* left;
TTNode* center;
TTNode* right;
};
Searching in a 2-3 tree
-
similar to binary search, except for the three-way branching
Inserting and deleting in a 2-3 tree
-
do not create new nodes at the bottom of the tree - they use split or merge and have effect higher in the tree
Insertion