Esempio n. 1
0
int main()
{
	
	//char rozkaz[30];
	char *rozkaz = malloc(sizeof *rozkaz);
	int index;
	printf("Wprowadz tekst:\n");


	//printf("%s", my_string);
	//lista *poczatek = malloc(sizeof *poczatek);
	//strcpy(poczatek->text, "karol");
	//poczatek->next = NULL;


	pierscien *root = malloc(sizeof *root);
	root->next = root;
	root->hash = NULL;
	root->before = root;
	root->wsk = NULL;

	while (true)
	{
		scanf("%30s", rozkaz);
		if (strcmp(rozkaz, "dodaj") == 0)
		{
			//char my_string[256];
			char *my_string = malloc(sizeof *my_string);
			scanf("%256s", my_string);
			*root = insert(root, my_string);
		}
		else if (strcmp(rozkaz, "pokaz") == 0)
		{
			//printf("Podaj wartosc hash: \n");
			
			scanf("%d", &index);
			show(root, index);
		}
		else if (strcmp(rozkaz, "wszystko") == 0)
		{
			show_everything(root);
		}
		else if (strcmp(rozkaz, "usun") == 0)
		{
			scanf("%d", &index);
			*root = usun(root, index);
		}
		
	}



	system("PAUSE");
	return 0;
}
int main()
{
  int totalTime;
  totalTime = 0;
  int quantum;
  int op;
  int cpp = 0;
  pcbCtrl *ctrl;
  pcbStates *states;
  groupsCtrl *ctrlG;
  usersCtrl *ctrlU;
  ctrl = malloc(sizeof(pcbCtrl));
  states = malloc(sizeof(pcbStates));
  states->readys = malloc(sizeof(pcbCtrl));
  states->waiting = malloc(sizeof(pcbCtrl));
  states->sleeping = malloc(sizeof(pcbCtrl));
  ctrlG = malloc(sizeof(groupsCtrl));
  ctrlU = malloc(sizeof(usersCtrl));

  printf("\n");

  quantum = set_int("Quantum del programa", 1);

  if(val_npos(quantum, 1) != FAIL)
  {
    do
    {
      printf("\n \t\t<< SIMULACION DE ALGORITMO DE DESPACHO RONUD-ROBIN >>\n");
      print_options(0);
      printf("\n>");
      scanf("%i",&op);
      getchar();

      switch(op)
      {
        case 1:
        printf("\n");
          create_group(ctrlG);
          break;
        case 2:
        printf("\n");
          create_user(ctrlU);
          break;
        case 3:
        printf("\n");
          create_process(cpp,ctrl,states,ctrlG,ctrlU);
          cpp++;
          break;
        case 4:
        printf("\n");
          state_change(ctrl,states);
          break;
        case 5:
        printf("\n");
          show_everything(ctrl,states,ctrlG,ctrlU);
          break;
        case 6:
        printf("\n");
          rr(states, ctrl, quantum, &totalTime);
          break;
        case 7:
        printf("\n");
          del_option(ctrl,states,ctrlG,ctrlU);
          break;
        case 8:
          break;
        default:
          printf("Opcion invalida, vuelva a intentarlo.\n");
      }
    }while(op != 8);

    if(ctrl->front != NULL)
    {
      pcb *aux = ctrl->front;
      while( next_pcb(&aux,ctrl->front) != FAIL )
      free(aux);
    }

    if(ctrlG->front != NULL)
    {
      groups *aux = ctrlG->front;
      while( next_group(&aux,ctrlG->front) != FAIL )
      free(aux);
    }

    if(ctrlU->front != NULL)
    {
      users *aux = ctrlU->front;
      while( next_user(&aux,ctrlU->front) != FAIL )
      free(aux);
    }

    free(ctrl->front);
    free(ctrlG->front);
    free(ctrlU->front);
    free(ctrl);
    free(ctrlG);
    free(ctrlU);
  }

  return 0;
}