示例#1
0
int main(){
    int t=10,i=0;
    for(i=1;i<=t;i++){ 
    int l,r,add,n,q,temp;
    scanf("%d %s",&n,arr);
    //printf("uo");
    createtree(arr,n);
    scanf("%d",&q);
    printf("Test %d:\n",i);
    while(q--){
        scanf("%d",&temp);
        if(temp)pointupdate(0,n-1,temp-1,0,0);
        else query()!=0?printf("YES\n"):printf("NO\n");
    }
    }
}
示例#2
0
void main()
{
	int i,n=7;
	int a[] = {2,5,3,-1,6,4,2};
	int m=n+1;
	int tree[m];
	init_tree(tree,m); //set every node to 0

	createtree(a,tree,n);

	printf("Fenwick Tree is:\n");
	for(i=0;i<m;i++)
	{
		printf("%d ",tree[i]);
	}
	
	//updatetree(a,tree,n,2,5); //index is 2 of a[] and new value is 5
	printf("\n%d\n",rsq(tree,m,2,5));
}
示例#3
0
文件: arr2tree.c 项目: sumedhm/ds
int main(){

	printf("\nPlease enter the value of n - ");
	scanf("%d", &n);

	int arr[n], i=0;
	printf("\n\nPlease enter the elements of sorted array:\n");
	while(i<n){
		scanf("%d", &arr[i]);i++;
	}

	root = (struct node *) malloc (sizeof(struct node));
	root->left = NULL;
	root->right = NULL;
	createtree(root, 0, n, arr);printf("\n\nPrinting tree\n");
	printtree(root);
	printf("\n\n-----------------------------------------\n");
	
	return 0;
}
示例#4
0
void func_1 (void)
{
  Ihandle *_cbox, *_cnv_1, *dlg, *img, 
    *_frm_1, *_frm_2, *_frm_3, *hbox, *_ctrl_1,
    *_list_1, *_list_2, *_list_3, *_text_1, *_ml_1;

  img = IupImage(32,32, img_bits1);
  IupSetHandle ("img1", img); 
  IupSetAttribute (img, "0", "0 0 0"); 
  IupSetAttribute (img, "1", "BGCOLOR");
  IupSetAttribute (img, "2", "255 0 0");

  img = IupImage(32,32, img_bits2);
  IupSetHandle ("img2", img); 
  IupSetAttribute (img, "0", "0 0 0"); 
  IupSetAttribute (img, "1", "0 255 0");
  IupSetAttribute (img, "2", "BGCOLOR");
  IupSetAttribute (img, "3", "255 0 0");

  _frm_1 = IupFrame(
    IupVbox(
      IupSetAttributes(IupButton("Button Text", NULL), "CINDEX=1"),
      IupSetAttributes(IupButton("", NULL), "IMAGE=img1,CINDEX=2"),
      IupSetAttributes(IupButton("", NULL), "IMAGE=img1,IMPRESS=img2,CINDEX=3"),
      NULL));
  IupSetAttribute(_frm_1,"TITLE","IupButton");
  IupSetAttribute(_frm_1,"CX","10");
  IupSetAttribute(_frm_1,"CY","180");

  _frm_2 = IupFrame(
    IupVbox(
      IupSetAttributes(IupLabel("Label Text"), "CINDEX=1"),
      IupSetAttributes(IupLabel(""), "SEPARATOR=HORIZONTAL,CINDEX=2"),
      IupSetAttributes(IupLabel(""), "IMAGE=img1,CINDEX=3"),
      NULL));
  IupSetAttribute(_frm_2,"TITLE","IupLabel");
  IupSetAttribute(_frm_2,"CX","200");
  IupSetAttribute(_frm_2,"CY","250");

  _frm_3 = IupFrame(
    IupVbox(
      IupSetAttributes(IupToggle("Toggle Text", NULL), "VALUE=ON,CINDEX=1"),
      IupSetAttributes(IupToggle("", NULL), "IMAGE=img1,IMPRESS=img2,CINDEX=2"),
      IupSetAttributes(IupFrame(IupRadio(IupVbox(
        IupSetAttributes(IupToggle("Toggle Text", NULL), "CINDEX=3"),
        IupSetAttributes(IupToggle("Toggle Text", NULL), "CINDEX=4"),
        NULL))), "TITLE=IupRadio"),
      NULL));
  IupSetAttribute(_frm_3,"TITLE","IupToggle");
  IupSetAttribute(_frm_3,"CX","400");
  IupSetAttribute(_frm_3,"CY","250");

  _text_1 = IupText( NULL);
  IupSetAttribute(_text_1,"VALUE","IupText Text");
  IupSetAttribute(_text_1,"SIZE","80x");
  IupSetAttribute(_text_1,"CINDEX","1");
  IupSetAttribute(_text_1,"CX","10");
  IupSetAttribute(_text_1,"CY","100");

  _ml_1 = IupMultiLine( NULL);
  IupSetAttribute(_ml_1,"VALUE","IupMultiline Text\nSecond Line\nThird Line");
  IupSetAttribute(_ml_1,"SIZE","80x60");
  IupSetAttribute(_ml_1,"CINDEX","1");
  IupSetAttribute(_ml_1,"CX","200");
  IupSetAttribute(_ml_1,"CY","100");

  _list_1 = IupList( NULL);
  IupSetAttribute(_list_1,"VALUE","1");
  IupSetAttribute(_list_1,"1","Item 1 Text");
  IupSetAttribute(_list_1,"2","Item 2 Text");
  IupSetAttribute(_list_1,"3","Item 3 Text");
  IupSetAttribute(_list_1,"CINDEX","1");
  IupSetAttribute(_list_1,"CX","10");
  IupSetAttribute(_list_1,"CY","10");

  _list_2 = IupList( NULL);
  IupSetAttribute(_list_2,"DROPDOWN","YES");
  IupSetAttribute(_list_2,"VALUE","2");
  IupSetAttribute(_list_2,"1","Item 1 Text");
  IupSetAttribute(_list_2,"2","Item 2 Text");
  IupSetAttribute(_list_2,"3","Item 3 Text");
  IupSetAttribute(_list_2,"CINDEX","2");
  IupSetAttribute(_list_2,"CX","200");
  IupSetAttribute(_list_2,"CY","10");

  _list_3 = IupList( NULL);
  IupSetAttribute(_list_3,"EDITBOX","YES");
  IupSetAttribute(_list_3,"VALUE","3");
  IupSetAttribute(_list_3,"1","Item 1 Text");
  IupSetAttribute(_list_3,"2","Item 2 Text");
  IupSetAttribute(_list_3,"3","Item 3 Text");
  IupSetAttribute(_list_3,"CINDEX","3");
  IupSetAttribute(_list_3,"CX","400");
  IupSetAttribute(_list_3,"CY","10");

  _cnv_1 = IupCanvas( NULL);
  IupSetAttribute(_cnv_1,"RASTERSIZE","100x100");
  IupSetAttribute(_cnv_1,"POSX","0");
  IupSetAttribute(_cnv_1,"POSY","0");
  IupSetAttribute(_cnv_1,"BGCOLOR","128 255 0");
  IupSetAttribute(_cnv_1,"CX","400");
  IupSetAttribute(_cnv_1,"CY","150");

  _ctrl_1 = IupVal(NULL);
  IupSetAttribute(_ctrl_1,"CX","600");
  IupSetAttribute(_ctrl_1,"CY","200");

  _cbox = IupCbox(
    _text_1,
    _ml_1,
    _list_1,
    _list_2,
    _list_3,
    _cnv_1,
    _ctrl_1,
    createtree(),
    create_mat(),
    _frm_1,
    _frm_2,
    _frm_3,
    NULL);
  IupSetAttribute(_cbox,"SIZE","480x200");

  hbox = IupSetAttributes(IupHbox(_cbox, NULL), "MARGIN=10x10");

  dlg = IupDialog(hbox);
  IupSetHandle("dlg",dlg);
  IupSetAttribute(dlg,"TITLE","Cbox Test");
}
示例#5
0
文件: cbox.c 项目: svn2github/iup-iup
void func_1 (void)
{
  Ihandle *_cbox, *_cnv_1, *dlg, *img, 
    *_frm_1, *_frm_2, *_frm_3, *hbox, *_ctrl_1,
    *_list_1, *_list_2, *_list_3, *_text_1, *_ml_1;

  img = IupImage(32,32, img_bits1);
  IupSetHandle ("img1", img); 
  IupSetAttribute (img, "0", "0 0 0"); 
  IupSetAttribute (img, "1", "BGCOLOR");
  IupSetAttribute (img, "2", "255 0 0");

  img = IupImage(32,32, img_bits2);
  IupSetHandle ("img2", img); 
  IupSetAttribute (img, "0", "0 0 0"); 
  IupSetAttribute (img, "1", "0 255 0");
  IupSetAttribute (img, "2", "BGCOLOR");
  IupSetAttribute (img, "3", "255 0 0");

  _frm_1 = IupFrame(
    IupVbox(
      IupSetAttributes(IupButton("Button Text", "action"), "BGCOLOR=\"255 128 0\", CINDEX=1"),
      IupSetAttributes(IupButton("", "action"), "BGCOLOR=\"255 128 0\", CINDEX=1"),
      IupSetAttributes(IupButton("", "action"), "IMAGE=img1,BGCOLOR=\"255 128 0\", CINDEX=2"),
      IupSetAttributes(IupButton("", "action"), "IMAGE=img1,BGCOLOR=\"255 128 0\", IMPRESS=img2,CINDEX=3"),
      NULL));
  IupSetAttribute(_frm_1,IUP_TITLE,"IupButton");
  IupSetAttribute(_frm_1,"CX","10");
  IupSetAttribute(_frm_1,"CY","180");

  _frm_2 = IupFrame(
    IupVbox(
      IupSetAttributes(IupLabel("Label Text"), "CINDEX=1,FONT=HELVETICA_ITALIC_14"),
      IupSetAttributes(IupLabel(""), "SEPARATOR=HORIZONTAL,CINDEX=2"),
      IupSetAttributes(IupLabel(""), "IMAGE=img1,CINDEX=3"),
      NULL));
  IupSetAttribute(_frm_2,IUP_TITLE,"IupLabel");
  IupSetAttribute(_frm_2,"CX","200");
  IupSetAttribute(_frm_2,"CY","250");

  _frm_3 = IupFrame(
    IupVbox(
      IupSetAttributes(IupToggle("Toggle Text", "action"), "VALUE=ON,CINDEX=1,FONT=HELVETICA_ITALIC_14"),
      IupSetAttributes(IupToggle("", "action"), "IMAGE=img1,IMPRESS=img2,CINDEX=2"),
      IupSetAttributes(IupFrame(IupRadio(IupVbox(
        IupSetAttributes(IupToggle("Toggle Text", "action"), "CINDEX=3"),
        IupSetAttributes(IupToggle("Toggle Text", "action"), "CINDEX=4"),
        NULL))), "TITLE=IupRadio"),
      NULL));
  IupSetAttribute(_frm_3,IUP_TITLE,"IupToggle");
  IupSetAttribute(_frm_3,"CX","400");
  IupSetAttribute(_frm_3,"CY","250");
  IupSetAttribute(_frm_3,"RASTERSIZE","150x150");

  _text_1 = IupText( "action");
  IupSetAttribute(_text_1,IUP_VALUE,"IupText Text");
  IupSetAttribute(_text_1,IUP_SIZE,"80x");
  IupSetAttribute(_text_1,"CINDEX","1");
  IupSetAttribute(_text_1,"CX","10");
  IupSetAttribute(_text_1,"CY","100");

  _ml_1 = IupMultiLine( "action");
  IupSetAttribute(_ml_1,IUP_VALUE,"IupMultiline Text\nSecond Line\nThird Line");
  IupSetAttribute(_ml_1,IUP_SIZE,"80x60");
  IupSetAttribute(_ml_1,"CINDEX","1");
  IupSetAttribute(_ml_1,"CX","200");
  IupSetAttribute(_ml_1,"CY","100");

  _list_1 = IupList( "action");
  IupSetAttribute(_list_1,IUP_VALUE,"1");
  IupSetAttribute(_list_1,"1","Item 1 Text");
  IupSetAttribute(_list_1,"2","Item 2 Text");
  IupSetAttribute(_list_1,"3","Item 3 Text");
  IupSetAttribute(_list_1,"CINDEX","1");
  IupSetAttribute(_list_1,"CX","10");
  IupSetAttribute(_list_1,"CY","10");

  _list_2 = IupList( "action");
  IupSetAttribute(_list_2,IUP_DROPDOWN,"YES");
  IupSetAttribute(_list_2,IUP_VALUE,"2");
  IupSetAttribute(_list_2,"1","Item 1 Text");
  IupSetAttribute(_list_2,"2","Item 2 Text");
  IupSetAttribute(_list_2,"3","Item 3 Text");
  IupSetAttribute(_list_2,"CINDEX","2");
  IupSetAttribute(_list_2,"CX","200");
  IupSetAttribute(_list_2,"CY","10");

  _list_3 = IupList( "action");
  IupSetAttribute(_list_3,"EDITBOX","YES");
  IupSetAttribute(_list_3,IUP_VALUE,"3");
  IupSetAttribute(_list_3,"1","Item 1 Text");
  IupSetAttribute(_list_3,"2","Item 2 Text");
  IupSetAttribute(_list_3,"3","Item 3 Text");
  IupSetAttribute(_list_3,"CINDEX","3");
  IupSetAttribute(_list_3,"CX","400");
  IupSetAttribute(_list_3,"CY","10");

  _cnv_1 = IupCanvas( "do_nothing");
  IupSetAttribute(_cnv_1,IUP_RASTERSIZE,"100x100");
  IupSetAttribute(_cnv_1,IUP_POSX,"0.0");
  IupSetAttribute(_cnv_1,IUP_POSY,"0.0");
  IupSetAttribute(_cnv_1,IUP_BGCOLOR,"128 255 0");
  IupSetAttribute(_cnv_1,"CX","400");
  IupSetAttribute(_cnv_1,"CY","150");

  _ctrl_1 = IupVal(NULL);
  IupSetAttribute(_ctrl_1,"CX","600");
  IupSetAttribute(_ctrl_1,"CY","200");

//  _cbox = IupCbox(
  _cbox = IupCboxBuilder(
    _text_1,
    _ml_1,
    _list_1,
    _list_2,
    _list_3,
    _cnv_1,
    _ctrl_1,
    createtree(),
    create_mat(),
    _frm_1,
    _frm_2,
    _frm_3,
    NULL);
  IupSetAttribute(_cbox,IUP_SIZE,"560x200");

  hbox = IupHbox(
           IupSetAttributes(IupFill(), "SIZE=10"), 
           IupVbox(
             IupSetAttributes(IupFill(), "SIZE=10"), 
             IupFrame(_cbox), 
             IupSetAttributes(IupLabel("Label Text"), "FONT=HELVETICA_ITALIC_14"),
             NULL), 
           NULL);

  dlg = IupDialog(hbox);
  IupSetHandle("dlg",dlg);
  IupSetAttribute(dlg,IUP_TITLE,"Cbox Test");
  IupSetAttribute(dlg,"COMPOSITED","YES");   /* improves a lot the redrawing */
//  IupSetAttribute(dlg,"FONT","HELVETICA_ITALIC_14");
}
示例#6
0
int main()
{

 initscr();
 curs_set(0);
 raw();
 start_color();
 init_pair(1,COLOR_RED,COLOR_BLACK);
 init_pair(2,COLOR_GREEN,COLOR_BLACK);
 init_pair(3,COLOR_YELLOW,COLOR_BLACK);
 init_pair(4,COLOR_WHITE,COLOR_BLACK);
 init_pair(5,COLOR_CYAN,COLOR_BLACK);
 init_pair(6,COLOR_MAGENTA,COLOR_BLACK);


  int k = 1,z;


  while(k)
   {
     attron(A_BOLD|COLOR_PAIR(1));

    for(i=3; i>=0; i--)
 	 {
 	 printw("\n (Tips: Use 0 for false & 1 for true) ");
   	 printw("\n PLEASE WAIT. LOADING PROJECT \n\n ");
 	 printw("\n\n Loaded %d%% \n",((3-i)*100/3));
 	 refresh();
 		system("sleep 1");
 		clear();
 	  }

    refresh();

    attron(A_UNDERLINE|A_REVERSE|COLOR_PAIR(2));
    printw("\n MICROPROJECT - DATA STRUCTURES (NOV 2014) ");
    printw("\n DEVELOPER - Aman Garg ");
    printw("\n ROLL - 13103050 \n");
    attroff(A_UNDERLINE|A_REVERSE);

    printw("\n\n Following data structures are available \n");

    printw("\n 1: Array Sorts ");
    printw("\n 2: Linked Lists ");
    printw("\n 3: Stacks ");
    printw("\n 4: Queues ");
    printw("\n 5: Trees ");
    printw("\n 6: Binary Search Trees ");
    printw("\n 7: AVL Trees ");
    printw("\n 0: Exit ");
    		attroff(COLOR_PAIR(2));
    		refresh();
		scanw("%d",&k);
    switch(k)
     {
       case 1:  					     //Arrays
       		system("clear ");
       		attron(COLOR_PAIR(3));
		printw("\n Enter number of elements : ");
		refresh();
  		scanw(" %d",&n);
  		printw("\n Enter %d (line separated) elements : \n",n);
  		refresh();

  		for(i=0;i<n ;i++ )
  		scanw("%d",&a[i]);

  		printw("\n Size of array is %d ",n);
		printw("\n The entered list : ");
 		for(i=0; i<n; i++)
 		{printw(" %d ",a[i]);
 		refresh();
 		}

        system("clear ");
 		endwin();
 		options_s(a);
		system("clear ");
		refresh();
   		attron(COLOR_PAIR(3));
   					break;

 	case 2:  {
 		  attron(COLOR_PAIR(4));
 		  system("clear ");					//Linked lists
 	 	  printw("\n 1: Singly Linked ");
    		  printw("\n 2: Doubly Linked ");
    		  printw("\n 0: Back 	\t");
    		  		refresh();
 	 	 		scanw("%d",&k);
 	 	 switch(k)
    		  {
    		  case 0:	system("clear "); main(); break;
 	 	  case 2:	{
 	 	  		system("clear ");
 	 	 		node *head=NULL;
 	 	 		endwin();
  		 		head=createlist();
  		 		system("clear ");
  		 		if(head) options_dl(head);
  		 		system("clear ");
  		 		refresh();
  		 		}	break;

 	 	  case 1:	{
 	 	  		system("clear ");
 	 	 		node *head=NULL;
 	 	 		endwin();
  		 		head=createlists();
  		 		system("clear ");
  		 		if(head) options(head);
  		 		system("clear ");
  		 		refresh();
  		 		}	break;
  		   }
  		 }	attroff(COLOR_PAIR(4)); break;

 								//stacks
 	case 3:
 		{
 		  attron(COLOR_PAIR(5));
 			system("clear ");
 	 	  printw("\n 1: Stacks using arrays ");
    		  printw("\n 2: Stacks using linked lists ");
    		  printw("\n 3: Polish Notations ");
    		  printw("\n 4: Tower of Hanoi ");
    		  printw("\n 0: Back 	\t");
    		  		refresh();
 	 	 		scanw("%d",&k);
 	 	 switch(k)

    		  {
    		  case 0:	system("clear "); main(); break;
    		  case 1:	{
    		  		 system("clear ");
    		  		 stack_a s;
    		  		 s.top=-1;
    		  		 endwin();
 				 options_sa(&s);
 				 system("clear ");
    		  		 refresh();
    		  		}	break;

    		  case 2:	{
    		  		 system("clear ");
    		  		 stack_l *top=NULL;
    		  		 endwin();
    		  		 options_sl(top);
    		  		 system("clear ");
    		  		 refresh();
    		  		}	break;


 	 	  case 3:	{
 	 	  		 system("clear ");
 	 	  		 stack k;
 	 	  		 endwin();
 	 	  		 create_p(&k);
 				 options_p(&k);
 				 system("clear ");
 				 refresh();
  		 		}	break;

 	 	  case 4:	{
 	 	  		 system("clear ");
 	 	  		 char src='A',tmp='C',dest='B' ;
 	 	  		 printw("\n Enter the number of disks ");
 	 	  		 refresh();
  				 scanw("%d",&z);
   				 TOH(z,src,tmp,dest);
   				 system("sleep 2");
   				 system("clear ");
   				 refresh();
 	 	  		}
 	 	  			break;
  		   }
  		 }	break;
 			attroff(COLOR_PAIR(5));
 	 		break;

 	case 4:
 			{
 			attron(COLOR_PAIR(6));
 				system("clear ");					//Queues
 	 	  printw("\n 1: Queues using arrays ");
    		  printw("\n 2: Queues using linked lists ");
    		  printw("\n 0: Back 	\t");
    		  		refresh();
    		  		scanw("%d",&k);
 	 	 switch(k)
    		  {
    		  case 0:	system("clear "); main(); break;
    		  case 1:	{system("clear ");
    		  		 front_a=-1;
    		  		 rear_a=-1;
    		  		 endwin();
    		  		 options_qa(&q);
    		  		 system("clear ");
    		  		 refresh();
    		  		}	break;

    		  case 2:	{system("clear ");
    		  		 count=0;
    		  		 front=NULL;
  				 rear=NULL;
  				 endwin();
   				 options_ql();
   				 system("clear ");
   				 refresh();
    		  		}	break;
  		   }
  		 }	break;
 			attroff(COLOR_PAIR(6));
 			break;

 								//Binary Tree
 	case 5:		{
 			   attron(COLOR_PAIR(1));
 			   system("clear ");
 			   printw("\n BINARY TREE PROGRAM \n");
 			   printw(" Enter (-1) wherever null \n\n");
 			   refresh();
   			   tree * root;
   			   tos=-1; fr=-1; rr=-1;
   			   system("sleep 2");
   			   endwin();
 			   root=createtree();
 			   system("clear ");
		           options_bt(root);
		           system("clear ");
		           refresh();
		           attroff(COLOR_PAIR(1));
 			}

 					break;
 								//Binary Search Tree
 	case 6:		{
 	  		  attron(COLOR_PAIR(3));
 	 		  system("clear ");
 			  printw("\n BINARY SEARCH TREE PROGRAM \n");
  			  printw(" Enter (-1) wherever null \n\n");
  			  refresh();
    			  tree *root=NULL;
    			  tos=-1; fr=-1; rr=-1;
    			  system("sleep 2");
    			  endwin();
     			  options_bst(root);
 			  system("clear ");
 			  refresh();
 			  attroff(COLOR_PAIR(3));
 			}

 					break;			//AVL Tree
 	case 7:		{
 	 		  attron(COLOR_PAIR(4));
 			  system("clear ");
 			  printw("\n AVL TREE PROGRAM \n");
  			  printw(" Enter (-1) wherever null \n\n");
  			  refresh();
  			  tree *root=NULL;
  			  tos=-1; fr=-1; rr=-1;
  			  system("sleep 2");
  			  endwin();
   			  options_av(root);
   			  system("clear ");
   			  refresh();
   			  attroff(COLOR_PAIR(4));
 			}

 					break;
 	case 0:
 		attroff(COLOR_PAIR(1));
 		system("clear ");
 		printw("\n Are you sure to exit : ");
 		refresh();
 		scanw("%d",&z);
 		if(z==1)
 		{

 		for(i=4; i>=0; i--)
 		  {

 		system("clear ");
 		printw("\n Exiting the execution : ");
 		printw("\n Removing core dumps . Please wait. \n");

 		printw("\n\n ACKNOWLEDGEMENTS : ");
 		printw("\n Ashish Sir ");

 		printw("\n\n REFERENCES : ");
 		printw("\n 1: Linux Manual : ");
 		printw("\n 2: Internet ");
 		printw("\n 3: DSA Books\n ");

 		printw("\n THANKS : \n");

 		printw("\n\n Releasing assets %d%% \n",((4-i)*100/4));
 		refresh();

 		system("sleep 1");
 		clear();
 		   }
 		   break;
 		}

 		else	system("clear "); main();


 		break;

 	default:

 		 printw("\n\n Wrong choice specified in the main menu \n");
 		 refresh();
 		 break;

      }

   }
   	attroff(COLOR_PAIR(1));
   	endwin();
   	return 0;
  }