This is comment for paste
Recursive Kernel
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void handle_open_port(unsigned int x);
- void handle_close_port(unsigned int x);
- unsigned int * previous_x = 0;
- void kernel_recursion(unsigned int x) {
- unsigned int current_previous_x = *previous_x;
- //printf("PREVIOUS_X: %u ADDRESS: %ld CURRENT_ADDRESS: %ld\n", current_previous_x, previous_x, (long)&x);
- previous_x = &x;
- if (x < current_previous_x) {
- handle_open_port(x); ++x;
- kernel_recursion(current_previous_x);--x;
- handle_close_port(x);
- } else if (current_previous_x < x) {
- handle_open_port(current_previous_x);
- kernel_recursion(current_previous_x + 1); --x;
- handle_close_port(current_previous_x);
- } else {
- handle_open_port(current_previous_x);
- handle_close_port(current_previous_x);
- }
- }
- void kernel(unsigned int x) {
- previous_x = &x;
- kernel_recursion(0);
- }
- int main() { kernel(10); }
- void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
- void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
Advertisement
Comments
-
- #include <stdio.h>
- void handle_open_port(unsigned int x);
- void handle_close_port(unsigned int x);
- void kernel_recursion(unsigned int x, unsigned int y) {
- handle_open_port(x);
- if (x < y) kernel_recursion(x+1, y);
- handle_close_port(x);
- }
- void kernel(unsigned int y) {
- kernel_recursion(0,y);
- }
- int main() { kernel(100); }
- void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
- void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
-
- #include <stdio.h>
- void handle_open_port(unsigned int x);
- void handle_close_port(unsigned int x);
- unsigned int y = 0;
- unsigned int z = 0;
- void kernel_recursion(unsigned int x) {
- y = z;
- handle_open_port(x);
- if (x < y) kernel_recursion(x + 1);
- handle_close_port(x);
- }
- void kernel(unsigned int limit) {
- y = z = limit;
- kernel_recursion(0);
- y = z = 0;
- }
- int main() { kernel(100); }
- void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
- void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
-
- #include <stdio.h>
- void handle_open_port(unsigned int x);
- void handle_close_port(unsigned int x);
- unsigned int y = 0;
- unsigned int z = 0;
- void kernel_recursion(unsigned int x) {
- z = y;
- handle_open_port(x);
- if (x < y) kernel_recursion(x + 1);
- handle_close_port(x);
- }
- void kernel(unsigned int limit) {
- y = z = limit;
- kernel_recursion(0);
- y = z = 0;
- }
- int main() { kernel(100); }
- void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
- void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
-
- #include <stdio.h>
- void handle_open_port(unsigned int x);
- void handle_close_port(unsigned int x);
- unsigned int y = 0;
- void kernel_recursion(unsigned int x) {
- handle_open_port(x);
- if (x < y) kernel_recursion(x + 1);
- handle_close_port(x);
- }
- void kernel(unsigned int limit) {
- y = limit;
- //TODO: Set y variable to have changed a maximum of 0 times
- kernel_recursion(0);
- //TODO: Unset y variable to have changed a maximum of 0 times
- }
- int main() { kernel(100); }
- void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
- void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
Add Comment
Please, Sign In to add comment