Stack stack (cleaned) (but not yet understood)
This commit is contained in:
parent
1adf316921
commit
16d0ea162d
|
@ -87,15 +87,8 @@ int widget_get_object_transparency (int i); // top
|
|||
// called in : src/widget/rules/distrib.c
|
||||
|
||||
// Define a structure for the stack
|
||||
#define MAX_SIZE 22
|
||||
typedef struct {
|
||||
// Array to store stack elements
|
||||
GtkWidget *arr[MAX_SIZE];
|
||||
// Index of the top element in the stack
|
||||
int top;
|
||||
} Stack;
|
||||
|
||||
int tuto_stack();
|
||||
#define MAX_SIZE 255
|
||||
typedef struct { GtkWidget *arr[MAX_SIZE]; int top; } Stack;
|
||||
|
||||
Stack get_stack();
|
||||
void set_stack (Stack *stack_new);
|
||||
|
@ -161,7 +154,6 @@ char *widget_get_text_address_any ();
|
|||
// used by : widget / rules.c
|
||||
|
||||
void *get_an_impression_of_what_a_rules_comparator_could_be();
|
||||
void *trying_to_fill_the_rules_comparator_from_stack();
|
||||
|
||||
/******************************************************************************/
|
||||
/* L A B O */
|
||||
|
|
|
@ -120,134 +120,6 @@ void widget_let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* gtk_box_append (compare_left, peek(&stack));
|
||||
// gtk_box_append (compare_right, peek(&stack));
|
||||
|
||||
|
||||
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/AMP.png")));
|
||||
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamine.png")));
|
||||
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamate.png")));
|
||||
|
||||
|
||||
|
||||
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamine.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/legumin.png")));
|
||||
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ATP.png")));
|
||||
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/histidine.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/phénylalanine.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/dopamine.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ribonuclease.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ascorbic acid.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/biotin.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/erythorbic acid.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/folic acid.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/glycerol.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/insuline.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/glutathione.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/lactic acid.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/pantothenic acid.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/pyridoxin.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/riboflavin.png")));
|
||||
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/hb.png")));
|
||||
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ADP.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamate.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamine.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/legumin.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ATP.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/histidine.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/phénylalanine.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/dopamine.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ribonuclease.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ascorbic acid.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/biotin.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/erythorbic acid.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/folic acid.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/glycerol.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/insuline.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/glutathione.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/lactic acid.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/pantothenic acid.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/pyridoxin.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/riboflavin.png")));
|
||||
gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/hb.png")));
|
||||
|
||||
|
||||
|
||||
GtkScrolledWindow *comparator = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new ());
|
||||
GtkBox *inside = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2));
|
||||
gtk_box_append (inside, GTK_WIDGET (compare_left));
|
||||
gtk_box_append (inside, GTK_WIDGET (compare_right));
|
||||
gtk_scrolled_window_set_child (comparator, GTK_WIDGET (inside));
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
"rule effect"
|
||||
"rule topic"
|
||||
|
|
|
@ -31,9 +31,6 @@
|
|||
#include "../../../../include/widget.h"
|
||||
#include "../../../../include/signal.h"
|
||||
|
||||
|
||||
// design a comparator (using 'before'/'after' stamps)
|
||||
|
||||
#define W_IMAGE_ABSURD 1920 / 32 // 1920 x 960 ad hoc (pour mon écran)
|
||||
#define H_IMAGE_ABSURD 960
|
||||
|
||||
|
@ -44,33 +41,6 @@ void set_stack (Stack *stack_new) {stack = *stack_new;}
|
|||
|
||||
// https://www.geeksforgeeks.org/implement-stack-in-c/
|
||||
|
||||
void *trying_to_fill_the_rules_comparator_from_stack(){
|
||||
|
||||
GtkBox *compare_left = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
|
||||
gtk_widget_set_size_request (GTK_WIDGET (compare_left), W_IMAGE_ABSURD, H_IMAGE_ABSURD);
|
||||
|
||||
// GtkBox *compare_right = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
|
||||
// gtk_widget_set_size_request (GTK_WIDGET (compare_right), W_IMAGE_ABSURD, H_IMAGE_ABSURD);
|
||||
|
||||
// while (!isEmpty(&stack)) {
|
||||
for (int i = 0; i < MAX_SIZE; i++) ;
|
||||
// gtk_box_append (compare_left, GTK_WIDGET (pop(&stack)));
|
||||
// gtk_box_append (compare_right, GTK_WIDGET (pop(&stack)));
|
||||
//}
|
||||
|
||||
GtkScrolledWindow *comparator = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new ());
|
||||
GtkBox *inside = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2));
|
||||
gtk_box_append (inside, GTK_WIDGET (compare_left));
|
||||
// gtk_box_append (inside, GTK_WIDGET (compare_right));
|
||||
// gtk_scrolled_window_set_child (comparator, GTK_WIDGET (inside));
|
||||
|
||||
return comparator;
|
||||
}
|
||||
|
||||
|
||||
#define W_IMAGE_ABSURD 1920 / 32 // 1920 x 960 ad hoc (pour mon écran)
|
||||
#define H_IMAGE_ABSURD 960
|
||||
|
||||
void *get_an_impression_of_what_a_rules_comparator_could_be(){
|
||||
|
||||
GtkBox *compare_left = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
|
||||
|
@ -79,22 +49,16 @@ void *get_an_impression_of_what_a_rules_comparator_could_be(){
|
|||
GtkBox *compare_right = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
|
||||
gtk_widget_set_size_request (GTK_WIDGET (compare_right), W_IMAGE_ABSURD, H_IMAGE_ABSURD);
|
||||
|
||||
Stack stack;// = get_stack();
|
||||
// Initialize the stack
|
||||
initialize(&stack);
|
||||
|
||||
push_images_onto_stack (stack);
|
||||
// set_stack (stack);
|
||||
|
||||
|
||||
// Push elements onto the stack and print the stack after each push
|
||||
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ATP.png")));
|
||||
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/ADP.png")));
|
||||
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("/home/jean/Gem-Graph/gem-graph-client/data/image/AMP.png")));
|
||||
//printf("Top element: %p\n", peek(&stack));q
|
||||
|
||||
gtk_box_append (compare_left, pop(&stack));
|
||||
gtk_box_append (compare_left, pop(&stack));
|
||||
|
@ -105,78 +69,55 @@ void *get_an_impression_of_what_a_rules_comparator_could_be(){
|
|||
gtk_box_append (comparator, GTK_WIDGET (compare_left));
|
||||
gtk_box_append (comparator, GTK_WIDGET (compare_right));
|
||||
|
||||
printf(" compare.c get_an_impression_of...()\n");
|
||||
return comparator;
|
||||
}
|
||||
|
||||
|
||||
// structure for the stack is in widget.h (^c^v...)
|
||||
void initialize (Stack *stack) { stack->top = -1; }
|
||||
bool isEmpty (Stack *stack) { return stack->top == -1; }
|
||||
bool isFull (Stack *stack) { return stack->top == MAX_SIZE - 1; }
|
||||
|
||||
void push (Stack *stack, GtkWidget *value)
|
||||
{
|
||||
// Check for stack overflow
|
||||
if (isFull(stack)) {
|
||||
printf("Stack Overflow\n");
|
||||
return;
|
||||
}
|
||||
// Increment top and add the value to the top of the stack
|
||||
if (isFull(stack)) { printf("Stack Overflow\n"); return; }
|
||||
stack->arr[++stack->top] = value;
|
||||
//printf("Pushed %p onto the stack\n", value);
|
||||
printf("%d ", stack->top);
|
||||
}
|
||||
|
||||
GtkWidget *pop (Stack *stack) {
|
||||
// Check for stack underflow
|
||||
if (isEmpty(stack)) {
|
||||
printf("Stack Underflow\n");
|
||||
return NULL;
|
||||
}
|
||||
// Return the top element
|
||||
GtkWidget *pop (Stack *stack)
|
||||
{
|
||||
if (isEmpty(stack)) { printf("Stack Underflow\n"); return NULL; }
|
||||
GtkWidget *popped = stack->arr[stack->top];
|
||||
// decrement top pointer
|
||||
stack->top--;
|
||||
printf("Popped %p from the stack %2d ", popped, stack->top);
|
||||
// return the popped element
|
||||
printf("Popped %p from the stack %2d ", popped, stack->top);
|
||||
if ((stack->top + 1) % 3 == 0) printf("\n");
|
||||
return popped;
|
||||
}
|
||||
|
||||
GtkWidget *peek(Stack *stack) {
|
||||
// Check if the stack is empty
|
||||
if (isEmpty(stack)) {
|
||||
printf("Stack is empty\n");
|
||||
return NULL;
|
||||
}
|
||||
// Return the top element without removing it
|
||||
GtkWidget *peek(Stack *stack)
|
||||
{
|
||||
if (isEmpty(stack)) { printf("Stack is empty\n"); return NULL; }
|
||||
return stack->arr[stack->top];
|
||||
}
|
||||
|
||||
|
||||
|
||||
int tuto_stack() {
|
||||
/*
|
||||
Stack stack;
|
||||
initialize(&stack);
|
||||
push(&stack, GTK_WIDGET (gtk_label_new ("222")));
|
||||
printf("Top element: %d\n", gtk_label_get_label (GTK_LABEL (peek(&stack))));
|
||||
push(&stack, GTK_WIDGET (gtk_label_new ("111"))); printf("Top element: %d\n", peek(&stack));
|
||||
push(&stack, GTK_WIDGET (gtk_label_new ("000"))); printf("Top element: %d\n", peek(&stack));
|
||||
while (!isEmpty(&stack)) {
|
||||
printf("Top element: %d ", peek(&stack));
|
||||
printf("Popped element: %d\n", gtk_label_get_label (GTK_LABEL (pop(&stack))));
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void *push_images_onto_stack (Stack stack)
|
||||
{
|
||||
clock_t start, end;
|
||||
printf("compare.c push_images_onto_stack() Init images stack\nStart filling stack >> ");
|
||||
|
||||
// initialize(&stack);
|
||||
printf("compare.c push_images_onto_stack() start >> ");
|
||||
start = clock();
|
||||
|
||||
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
|
||||
|
@ -226,19 +167,6 @@ void *push_images_onto_stack (Stack stack)
|
|||
|
||||
end = clock();
|
||||
long double t = (long double)(end - start) / CLOCKS_PER_SEC;
|
||||
printf(" << stack filled in %9Lg sec\n", t);
|
||||
|
||||
|
||||
|
||||
|
||||
// Pop elements from the stack and print the stack after each pop
|
||||
/*
|
||||
while (!isEmpty(&stack)) printf("Popped element: %p\n", pop(&stack));
|
||||
* ...
|
||||
Popped 0xf5e03b0 from the stack 0 Popped element: 0xf5e03b0
|
||||
Popped 0xf5bf500 from the stack -1 Popped element: 0xf5bf500
|
||||
make: *** [Makefile:70: run] Erreur de segmentation
|
||||
*/
|
||||
printf(" << %9Lg sec\n", t);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,9 +52,6 @@ void *widget_get_rules_tree_tools ()
|
|||
GtkBox *rules_tree_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
|
||||
gtk_box_append (rules_tree_box, GTK_WIDGET (widget_get_user_rules_tree()));
|
||||
gtk_box_append (rules_tree_box, GTK_WIDGET (widget_get_rules_use ()));
|
||||
// push_images_onto_stack ();
|
||||
// trying_to_fill_the_rules_comparator_from_stack();
|
||||
// tuto_stack ();
|
||||
gtk_box_append (rules_tree_box, GTK_WIDGET (get_an_impression_of_what_a_rules_comparator_could_be()));
|
||||
return GTK_WIDGET (rules_tree_box);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue