Ejemplo n.º 1
0
int main ()
{
  std::set<int> first;                           // empty set of ints

  int myints[]= {10,20,30,40,50};
  std::set<int> second (myints,myints+5);        // range
  //find and delete
  std::set<int>::iterator it;
  it = second.find (50);
  second.erase (it);
  
  //insert
  second.insert(1);
  

  std::set<int> third (second);                  // a copy of second

  std::set<int> fourth (second.begin(), second.end());  // iterator ctor.

  bool(*fn_pt)(int,int) = fncomp;
  std::set<int,bool(*)(int,int)> sixth (fn_pt);  // function pointer as Compare
	  
  std::set<int,classcomp> fifth(myints,myints+5);                 // class as Compare
  std::set<int,classcomp>::iterator iter = fifth.begin();
  while(iter != fifth.end())
  {
	  std::cout<<*iter<<std::endl;
	  iter++;
  }

  return 0;
}
Ejemplo n.º 2
0
int main ()
{
  //!NOTE: should work perfectly now.
  ExampleOfUsingClassComp();

  // empty set that can contain ints
  std::set<int> first;

  int myints[]= {40,50,10,30,20};
  std::set<int> second (myints,myints+5);
  // This should be printed in order; set has an internal
  // comparator that 'looks' and 'works' like those given above.
  //!NOTE: We replace the for loop below with 'PrintSetContents'
  // for(std::set<int>::const_iterator cit = second.begin();
  //     cit != second.end(); cit++)
  //   std::cout << (*cit) << " ";
  // std::cout << std::endl;
  PrintSetContents(second.begin(), second.end());

  // a copy of second
  std::set<int> third (second);

  // Constructor that takes iterators
  std::set<int> fourth (second.begin(), second.end());

  // class/struct as Compare object
  std::set<int,classcomp<int> > fifth;

  // function pointer as Compare method
  bool(*fn_pt)(int,int) = fncomp;
  std::set<int,bool(*)(int,int)> sixth (second.begin(),
                                        second.end(), fn_pt);
  // Should print elements reversed
  for(std::set<int,bool(*)(int,int)>::iterator it = sixth.begin();
      it != sixth.end(); it++)
    std::cout << (*it)  << " ";
  std::cout << std::endl;

  char str[] = "For... He's a Jolly Good Fellow!.."
               "For He's a Jolly Good Fellow!..."
               "And so say all of us, and so say all of us."
               "I WISH TO WISH THE WISH YOU WISH TO WISH,"
               "BUT IF YOU WISH THE WISH THE WITCH WISHES, "
               "I WON'T WISH THE WISH YOU WISH TO WISH."
               "@#^&@)*(^%$#!$#&(*#!@$#!~~`1;/.,''`)";
  std::set<char> chara(str, str + strlen(str));
  //!NOTE: We replace the for loop below with 'PrintSetContents'
  // for(std::set<char>::const_iterator cch = chara.begin();
  //     cch != chara.end(); cch++)
  //   std::cout << (*cch);
  // std::cout << std::endl;
  //!TODO: comment out the line below, compile & run. Note what
  //       happens.
  PrintSetContents(chara.begin(), chara.end());
  return 0;
}
//Menu algoritmos de repetiçao
void load_alg_loop_while (void)
{
	do
	{
		printf("\n\t../Loop Algorithms - While \n");
		printf("\nPlease choose one of the following options:\n");

		printf("_____________________________________________________\n\n");
		printf("1......................................................\n");
		printf("2......................................................\n");
		printf("3......................................................\n");
		printf("4......................................................\n");
		printf("5......................................................\n");
		printf("6......................................................\n");
		printf("7......................................................\n");
		printf("8.Return\n");
		printf("9.Exit\n");

		printf("_____________________________________________________\n\n");
		printf("\t\tEnter Choice: ");
		scanf("%u", &choice);

		system("clear");

		switch (choice)
		{
			case 1: first();
				break;
			case 2: second();
				break;
			case 3: third();
				break;
			case 4: fourth();
				break;
			case 5: fifth();
				break;
			case 6: sixth();
				break;
			case 7: seventh();
				break;
			case 8:load_alg_loop();
				break;
			case 9: printf("\nQuitting program!\n");
				exit(FLAG);
				break;
			default: printf("\nInvalid choice!\n");
				break;
		}
	} while (choice != 9);
}
Ejemplo n.º 4
0
int set_main ()
{
  std::set<int> first;                           // empty set of ints

  int myints[]= {10,20,30,40,50};
  std::set<int> second (myints,myints+5);        // range

  std::set<int> third (second);                  // a copy of second

  std::set<int> fourth (second.begin(), second.end());  // iterator ctor.

  std::set<int,classcomp> fifth;                 // class as Compare

  bool(*fn_pt)(int,int) = fncomp;
  std::set<int,bool(*)(int,int)> sixth (fn_pt);  // function pointer as Compare

  std::cout << "done";
  return 0;
}
//Menu algorithmos condicionais
void load_alg_conditional(void)
{
	do
	{
		printf("\n\t../Conditional Algorithms \n");
		printf("\nPlease choose one of the following options:\n");

		printf("______________________________________________________\n\n");
		printf("1.------------------------------------------------------\n");
		printf("2.------------------------------------------------------\n");
		printf("3.------------------------------------------------------\n");
		printf("4.------------------------------------------------------\n");
		printf("5.------------------------------------------------------\n");
		printf("6.------------------------------------------------------\n");
		printf("7.------------------------------------------------------\n");
		printf("8.------------------------------------------------------\n");
		printf("9.------------------------------------------------------\n");
		printf("10.-----------------------------------------------------\n");
		printf("11.-----------------------------------------------------\n");
		printf("12.Return...\n");
		printf("13.Exit\n");

		printf("_____________________________________________________\n\n");
		printf("\t\tEnter Choice: ");
		scanf("%u", &choice);

		system("clear");

		 switch(choice)
		{
			case 1: first();
				break;
			case 2: second();
				break;
			case 3: third();
				break;
			case 4: fourth();
				break;
			case 5: fifth();
				break;
			case 6: sixth();
				break;
			case 7: seventh();
				break;
			case 8: eighth();
				break;
			case 9: ninth();
				break;
			case 10: tenth();
				break;
			case 11: eleventh();
				break;
			case 12: load_menu();
				break;
			case 13: printf("\n Quitting program!\n");
				exit(FLAG);
				break;
			default: printf("\n Invalid choice!\n");
				break;
		}
	} while (choice != 8);
}