Program to generate Cantor ternary set
More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
|
typedef struct _cantor_set | CantorSet |
| structure to define Cantor set
|
|
Program to generate Cantor ternary set
◆ free_memory()
Clear memory allocated by propagate function.
- Parameters
-
head | pointer to first allocated instance. |
void free_memory(CantorSet *head)
Clear memory allocated by propagate function.
Definition: cantor_set.c:72
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition: malloc_dbg.h:26
◆ main()
int main |
( |
int |
argc, |
|
|
char const * |
argv[] |
|
) |
| |
Main function.
86 int start_num, end_num, levels;
90 printf(
"Enter 3 arguments: start_num \t end_num \t levels\n");
91 scanf(
"%d %d %d", &start_num, &end_num, &levels);
95 start_num = atoi(argv[1]);
96 end_num = atoi(argv[2]);
97 levels = atoi(argv[3]);
100 if (start_num < 0 || end_num < 0 || levels < 0)
102 fprintf(stderr,
"All numbers must be positive\n");
106 CantorSet head = {.start = start_num, .end = end_num, .next = NULL};
109 for (
int i = 0; i < levels; i++)
111 printf(
"Level %d\t", i);
116 printf(
"Level %d\t", levels);
void propagate(CantorSet *head)
Iterative constructor of all sets in the current level.
Definition: cantor_set.c:23
void print(CantorSet *head)
Print sets in the current range to stdout
Definition: cantor_set.c:55
structure to define Cantor set
Definition: cantor_set.c:12
◆ print()
Print sets in the current range to stdout
- Parameters
-
head | pointer to first set in the current level |
61 printf(
"[%lf] -- ", temp->start);
62 printf(
"[%lf]", temp->end);
◆ propagate()
Iterative constructor of all sets in the current level.
This function dynamically allocates memory when creating new sets. These are freed by the function free_memory.
- Parameters
-
head | pointer to interval set instance to update |
35 double diff = (((temp->end) - (temp->start)) / 3);
39 temp->end = ((temp->start) + diff);
node * newNode(int data)
The node constructor, which receives the key value input and returns a node pointer.
Definition: binary_search_tree.c:28
#define malloc(bytes)
This macro replace the standard malloc function with malloc_dbg.
Definition: malloc_dbg.h:18