[Avl-cvs] avl/src Makefile,1.6,1.7 avl.cpp,1.11,1.12 test.cpp,1.10,1.11
Brought to you by:
hetfield666,
jah2003
From: Patrizio B. <het...@us...> - 2004-09-07 10:40:32
|
Update of /cvsroot/avl/avl/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27121 Modified Files: Makefile avl.cpp test.cpp Log Message: new gtk gui. NOT WORKING! Index: avl.cpp =================================================================== RCS file: /cvsroot/avl/avl/src/avl.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** avl.cpp 6 Sep 2004 14:12:06 -0000 1.11 --- avl.cpp 7 Sep 2004 10:40:17 -0000 1.12 *************** *** 24,27 **** --- 24,170 ---- using namespace std; + void p(){ + Bst* bst=new Bst(); + + + for (int i=0;i<1500;i++) { + + bst->insert(i); + } + + } + + + int choice=0; + int base_tree=20; + int upperbound=2; + Test *prova=NULL; + Avlt* aux_avl=NULL; + Bst* aux_bst=NULL; + + #ifdef GUI + + GtkWidget *node_list=NULL; + GtkWidget *vpaned1=NULL; + GtkWidget *spinbutton1=NULL; + GtkWidget *spinbutton2=NULL; + + void bst_select() { + choice=1; + } + + void avl_select() { + choice=0; + } + + void comparation_select() { + choice=2; + } + void start() { + + //Test *prova; + //prova= new Test(); + //Avlt* aux_avl=NULL; + //Bst* aux_bst=NULL; + + base_tree=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton1)); + upperbound=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton2)); + printf("%d %d %d\n", choice,base_tree, upperbound ); + + /* + if (choice==0) { + printf("Processing AVL, wait\n"); + prova = new Test(0,upperbound,base_tree); + aux_avl=prova->getAvlt(); + printf("Processing AVL2, wait\n"); + return; + } + if (choice==1) { + + prova = new Test(1,upperbound,base_tree); + aux_bst=prova->getBst(); + } + if (choice==2) { + prova = new Test(2,upperbound,base_tree); + } + */ + GtkWidget *scrolled_window; + GtkWidget *tree_view; + GtkTreeIter iter1; + GtkTreeStore *store; + GtkCellRenderer *cell; + GtkTreeViewColumn *column; + + //creo una contenitore che sia scrollabile + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + //creo il contenitore dell'albero + store=gtk_tree_store_new(1,G_TYPE_STRING); + + //creo l'albero e lo lego al contenitore + tree_view = gtk_tree_view_new (); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), tree_view); + + //link dell'albero e il suo contenitore + gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (store)); + gtk_widget_show (tree_view); + + gtk_tree_store_append (GTK_TREE_STORE (store), &iter1,NULL); + gtk_tree_store_set (GTK_TREE_STORE (store), &iter1, 0, "Prova", -1); + + //finalizzazione: creo una cella e metto in una colonna, che poi metto nell'albero. + cell = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("AVL Tree",cell,"text", 0, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), GTK_TREE_VIEW_COLUMN (column)); + + gtk_widget_destroy(node_list); + node_list=scrolled_window; + + //if (choice==0) node_list = aux_avl->print_best_look(); + // if (choice==1) node_list = aux_bst->print_best_look(); + + gtk_paned_add1 (GTK_PANED (vpaned1), node_list); + gtk_widget_show (node_list); + gtk_widget_show (vpaned1); + } + + + GtkWidget* node_list_start() { + + GtkWidget *scrolled_window; + GtkWidget *tree_view; + GtkTreeIter iter1; + GtkTreeStore *store; + GtkCellRenderer *cell; + GtkTreeViewColumn *column; + + //creo una contenitore che sia scrollabile + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + //creo il contenitore dell'albero + store=gtk_tree_store_new(1,G_TYPE_STRING); + + //creo l'albero e lo lego al contenitore + tree_view = gtk_tree_view_new (); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), tree_view); + + //link dell'albero e il suo contenitore + gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (store)); + gtk_widget_show (tree_view); + + gtk_tree_store_append (GTK_TREE_STORE (store), &iter1,NULL); + gtk_tree_store_set (GTK_TREE_STORE (store), &iter1, 0, "Empty", -1); + + //finalizzazione: creo una cella e metto in una colonna, che poi metto nell'albero. + cell = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("AVL Tree",cell,"text", 0, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), GTK_TREE_VIEW_COLUMN (column)); + + return scrolled_window; //ritorno l'oggetto, nel main viene visualizzato e appeso alla finestra principale. + + } + #endif int main(int argc, char *argv[]) { *************** *** 31,95 **** // 2= test comparativo ! Test *prova=NULL; ! Avlt* aux_avl=NULL; ! Bst* aux_bst=NULL; ! ! int upper_bound=1000; ! int base_tree=10000; printf("Welcome to AVL/BST test program\nYou will be asked for values, no controls on your imput, so be careful!\n"); printf("What do you want to test? AVL=0 BST=1 Comparation=2\n"); - int choice; scanf("%d",&choice); printf("Insert the initial number of items\n"); scanf("%d",&base_tree); printf("Insert the number of changements you want to do on the tree\n"); ! scanf("%d",&upper_bound); if (choice==0) { printf("Processing AVL, wait\n"); ! prova = new Test(0,upper_bound,base_tree); aux_avl=prova->getAvlt(); } if (choice==1) { printf("Processing BST, wait\n"); ! prova = new Test(1,upper_bound,base_tree); aux_bst=prova->getBst(); } if (choice==2) { printf("Comparation on the way, wait\n"); ! prova = new Test(2,upper_bound,base_tree); } ! ! #ifndef GUI ! if (choice==0) aux_avl->print_best_look(); ! if (choice==1) aux_bst->print_best_look(); ! #else ! if (choice==0 || choice==1) { ! GtkWidget *window=NULL; ! GtkWidget *vpaned=NULL; ! GtkWidget *node_list=NULL; ! ! gtk_init (&argc, &argv); ! char* fullname="AVL Tree Visualization"; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), fullname); ! g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 15); - gtk_widget_set_size_request (GTK_WIDGET (window), 500, 450); ! vpaned = gtk_vpaned_new (); ! gtk_container_add (GTK_CONTAINER (window), vpaned); ! gtk_widget_show (vpaned); ! if (choice==0) node_list = aux_avl->print_best_look(); ! if (choice==1) node_list = aux_bst->print_best_look(); ! ! gtk_paned_add1 (GTK_PANED (vpaned), node_list); gtk_widget_show (node_list); --- 174,329 ---- // 2= test comparativo ! #ifndef GUI ! printf("Welcome to AVL/BST test program\nYou will be asked for values, no controls on your imput, so be careful!\n"); printf("What do you want to test? AVL=0 BST=1 Comparation=2\n"); scanf("%d",&choice); printf("Insert the initial number of items\n"); scanf("%d",&base_tree); printf("Insert the number of changements you want to do on the tree\n"); ! scanf("%d",&upperbound); if (choice==0) { printf("Processing AVL, wait\n"); ! prova = new Test(0,upperbound,base_tree); aux_avl=prova->getAvlt(); } if (choice==1) { printf("Processing BST, wait\n"); ! prova = new Test(1,upperbound,base_tree); aux_bst=prova->getBst(); } if (choice==2) { printf("Comparation on the way, wait\n"); ! prova = new Test(2,upperbound,base_tree); } ! if (choice==0) aux_avl->print_best_look(); ! if (choice==1) aux_bst->print_best_look(); ! #else + GtkWidget *window=NULL; + GtkWidget *vpaned2=NULL; + GtkWidget *button=NULL; + GtkWidget *box1=NULL; + GtkWidget *box2=NULL; + GtkWidget *box3=NULL; + GtkWidget *box4=NULL; + GtkWidget *box5=NULL; + GSList *group=NULL; + GtkAdjustment *adj=NULL; + GtkWidget *label=NULL; + //Test *a=new Test(); + p(); + gtk_init (&argc, &argv); + p(); + //Test *a=new Test(); + char* fullname="AVL Tree Visualization"; + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), fullname); ! gtk_widget_set_usize(window, (int)gdk_screen_width()*0.75, (int)gdk_screen_height()*0.75); ! g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 15); ! vpaned1 = gtk_vpaned_new (); ! gtk_container_add (GTK_CONTAINER (window), vpaned1); ! gtk_widget_show (vpaned1); ! vpaned2 = gtk_vpaned_new (); ! gtk_widget_show (vpaned2); ! ! box1 = gtk_vbox_new (FALSE, 0); ! gtk_container_add (GTK_CONTAINER (vpaned2), box1); ! gtk_widget_show (box1); ! ! box2 = gtk_hbox_new (FALSE, 10); ! gtk_container_set_border_width (GTK_CONTAINER (box2), 10); ! gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); ! gtk_widget_show (box2); ! ! box3 = gtk_hbox_new (FALSE, 10); ! gtk_container_set_border_width (GTK_CONTAINER (box3), 10); ! gtk_box_pack_start (GTK_BOX (box1), box3, TRUE, TRUE, 0); ! gtk_widget_show (box3); ! ! box4 = gtk_hbox_new (FALSE, 10); ! gtk_container_set_border_width (GTK_CONTAINER (box4), 10); ! gtk_box_pack_start (GTK_BOX (box1), box4, TRUE, TRUE, 0); ! gtk_widget_show (box4); ! ! box5 = gtk_hbox_new (FALSE, 10); ! gtk_container_set_border_width (GTK_CONTAINER (box5), 10); ! gtk_box_pack_start (GTK_BOX (box1), box5, TRUE, TRUE, 0); ! gtk_widget_show (box5); ! ! label = gtk_label_new ("What do you want to test?"); ! gtk_label_set_justify(GTK_LABEL (label),GTK_JUSTIFY_LEFT); ! gtk_box_pack_start (GTK_BOX (box2), label, TRUE, TRUE, 0); ! gtk_widget_show (label); ! ! button = gtk_radio_button_new_with_label (NULL, "AVL"); ! g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (avl_select),G_OBJECT (button)); ! gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); ! gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); ! gtk_widget_show (button); ! ! group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)); ! button = gtk_radio_button_new_with_label (group, "BST"); ! g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (bst_select),G_OBJECT (button)); ! gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); ! gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); ! gtk_widget_show (button); ! ! button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (button), "Comparation"); ! g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (comparation_select),G_OBJECT (button)); ! gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); ! gtk_widget_show (button); ! ! label = gtk_label_new ("Select the number of nodes of the tree"); ! gtk_label_set_justify(GTK_LABEL (label),GTK_JUSTIFY_LEFT); ! gtk_box_pack_start (GTK_BOX (box3), label, TRUE, TRUE, 0); ! gtk_widget_show (label); ! ! adj = (GtkAdjustment *) gtk_adjustment_new (500, 0, 10000000, 200, 0, 0); ! spinbutton1 = gtk_spin_button_new (adj, 0, 0); ! gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinbutton1), FALSE); ! gtk_spin_button_set_numeric(GTK_SPIN_BUTTON (spinbutton1), TRUE); ! gtk_spin_button_set_value(GTK_SPIN_BUTTON (spinbutton1), 10000); ! gtk_box_pack_start (GTK_BOX (box3), spinbutton1, FALSE, TRUE, 0); ! gtk_widget_show (spinbutton1); ! ! label = gtk_label_new ("Select the number of operations on the tree"); ! gtk_label_set_justify(GTK_LABEL (label),GTK_JUSTIFY_LEFT); ! gtk_box_pack_start (GTK_BOX (box4), label, TRUE, TRUE, 0); ! gtk_widget_show (label); ! ! adj = (GtkAdjustment *) gtk_adjustment_new (500, 0, 10000000, 200, 0, 0); ! spinbutton2 = gtk_spin_button_new (adj, 0, 0); ! gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinbutton2), FALSE); ! gtk_spin_button_set_numeric(GTK_SPIN_BUTTON (spinbutton2), TRUE); ! gtk_spin_button_set_value(GTK_SPIN_BUTTON (spinbutton2), 1000); ! gtk_box_pack_start (GTK_BOX (box4), spinbutton2, FALSE, TRUE, 0); ! gtk_widget_show (spinbutton2); ! ! button = gtk_button_new_with_label ("start"); ! g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (start), G_OBJECT (window)); ! gtk_box_pack_start (GTK_BOX (box5), button, FALSE, TRUE, 55); ! gtk_widget_show (button); ! ! button = gtk_button_new_with_label ("close"); ! g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (gtk_main_quit), G_OBJECT (window)); ! gtk_box_pack_start (GTK_BOX (box5), button, FALSE, TRUE, 65); ! gtk_widget_show (button); ! ! node_list=node_list_start(); ! ! gtk_paned_add1 (GTK_PANED (vpaned1), node_list); ! gtk_paned_add2 (GTK_PANED (vpaned1), vpaned2); ! gtk_widget_show (node_list); *************** *** 97,102 **** gtk_main (); ! } #endif return EXIT_SUCCESS; } --- 331,338 ---- gtk_main (); ! ! #endif + return EXIT_SUCCESS; } Index: Makefile =================================================================== RCS file: /cvsroot/avl/avl/src/Makefile,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Makefile 6 Sep 2004 13:16:33 -0000 1.6 --- Makefile 7 Sep 2004 10:40:17 -0000 1.7 *************** *** 3,6 **** --- 3,7 ---- ifdef gtk_gui CC=g++ -O2 -Wall -W `pkg-config gtk+-2.0 --cflags` -DGUI -g + #CC=g++ `pkg-config gtk+-2.0 --cflags` -DGUI else CC=g++ -O2 -Wall -W Index: test.cpp =================================================================== RCS file: /cvsroot/avl/avl/src/test.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** test.cpp 6 Sep 2004 17:03:40 -0000 1.10 --- test.cpp 7 Sep 2004 10:40:17 -0000 1.11 *************** *** 52,61 **** random=rand()%tree_dimensions; avlt=avlt->insert(random); - // insertion_list.push_back(random); } end = clock(); init_timer = ((double) (end - start)) / CLOCKS_PER_SEC; printf("AVL Initialization of %d items tree took %lf seconds\n",base_limit,init_timer); - // getchar(); } --- 52,59 ---- *************** *** 65,74 **** random=rand()%tree_dimensions; bst->insert(random); - // insertion_list.push_back(random); } end = clock(); init_timer = ((double) (end - start)) / CLOCKS_PER_SEC; printf("BST Initialization of %d items tree took %lf seconds\n",base_limit,init_timer); - // getchar(); } } --- 63,70 ---- *************** *** 96,100 **** avlt=avlt->insert(random); insertion_list.push_back(random); - //printf("inserted number %d\n",random); insert_counter++; } --- 92,95 ---- *************** *** 123,128 **** change_timer = ((double) (end - start)) / CLOCKS_PER_SEC; printf("AVL TEST RESULTS:\n%d insertions and %d deletions took %lf seconds.\nTotal of %d cycles, wasted:%d\n",insert_counter,erase_counter,change_timer,upper_limit,waste); ! printf("press Return to exit\n"); ! //getchar(); } --- 118,122 ---- change_timer = ((double) (end - start)) / CLOCKS_PER_SEC; printf("AVL TEST RESULTS:\n%d insertions and %d deletions took %lf seconds.\nTotal of %d cycles, wasted:%d\n",insert_counter,erase_counter,change_timer,upper_limit,waste); ! } *************** *** 147,155 **** random=rand()%tree_dimensions; decision=rand()%2; - //decision=0; if (decision==0) { bst->insert(random); insertion_list.push_back(random); - //printf("inserted number %d\n",random); insert_counter++; } --- 141,147 ---- *************** *** 176,181 **** change_timer = ((double) (end - start)) / CLOCKS_PER_SEC; printf("BST TEST RESULTS:\n%d insertions and %d deletions took %lf seconds.\nTotal of %d cycles, wasted %d\n",insert_counter,erase_counter,change_timer,upper_limit,waste); ! printf("press Return to exit\n"); ! //getchar(); } --- 168,172 ---- change_timer = ((double) (end - start)) / CLOCKS_PER_SEC; printf("BST TEST RESULTS:\n%d insertions and %d deletions took %lf seconds.\nTotal of %d cycles, wasted %d\n",insert_counter,erase_counter,change_timer,upper_limit,waste); ! } *************** *** 234,237 **** --- 225,229 ---- base_tree_size è la dimensione dell'albero */ + bst = avlt = NULL; tree_dimensions=base_tree_size; |