コード例 #1
0
int main(int argc, char *argv[]) {
	int i, j;
	int N = atoi(argv[1]);
	
	srand(time(NULL));
	
	Q queues[M];

	for (i = 0; i < M; ++i) {
		queues[i] = QUEUEinit(N);
	}

	for (i = 0; i < N; ++i) {
		QUEUEput(queues[rand() % M], i);
	}

	for (i = 0; i < M; ++i) {
		for (j = 0; !QUEUEempty(queues[i]); ++j) {
			printf("%3d ", QUEUEget(queues[i]));
		}
		printf("\n");
	}
	
	return 0;
}
コード例 #2
0
ファイル: 5.88.c プロジェクト: LinuxKernelDevelopment/ALC
void traverse(link h, void (*visit)(link))
{
 QUEUEinit(max); QUEUEput(h);
 while (!QUEUEempty())
 {
   (*visit)(h = QUEUEget());
   if (h->l != NULL) QUEUEput(h->l);
   if (h->r != NULL) QUEUEput(h->r);
 }
}
int main(void) 
{
  int n = 100, i;
  
  QUEUEinit(n-1);
  for(i = 1; i < n; i++)
    QUEUEput(i);
  for (i = 0; i < F; i++)
    printf("%d\n", QUEUEget());
  return 0;
}
コード例 #4
0
void traverse(int k)
{
  link t;
  QUEUEinit(V); QUEUEput(k);
  while (!QUEUEempty())
    if (visited[k = QUEUEget()] == 0) {
      printf("visit %d\n", k); visited[k] = 1;
      for (t = adj[k]; t != NULL; t = t->next)
	if (visited[t->v] == 0) QUEUEput(t->v);
    }
}
int main(void) 
{
  int n;

  printf("Enter the length of the queue: ");
  scanf("%d", &n);
  QUEUEinit(n);
  QUEUEput(1);
  QUEUEput(2);
  printf("%d ", QUEUEget());
  printf("%d\n", QUEUEget());
  return 0;
}
int main(void) 
{
  int n = 4;
  
  QUEUEinit(n);
  QUEUEput('a');
  QUEUEput('b');
  QUEUEput('c');
  printf("%c\n", QUEUEget());
  printf("%c\n", QUEUEget());
  printf("%c\n", QUEUEget());
  return 0;
}
コード例 #7
0
ファイル: proj2.c プロジェクト: edujanicas/Cheques
int main(){

    int valor;
    long int refe, refb, refc, ref;
    char command[CMD_LENGTH] = "";

    STinit(&clientes);
    cheques = QUEUEinit(10);
    scanf("%s",command);

    while(strcmp(command,"sair")){

        if(!strcmp(command,"cheque")){
            scanf("%d%ld%ld%ld",&valor,&refe,&refb,&refc);
            adiciona_cheque(valor,refe,refb,refc);
        }

        else if(!strcmp(command,"processa"))
            processa_cheque();

        else if(!strcmp(command,"processaR")){
            scanf("%ld",&refc);
            processa_cheque_ref(refc);
        }

        else if(!strcmp(command,"infocheque")){
            scanf("%ld",&ref);
            info_cheque(ref);
        }

        else if(!strcmp(command,"infocliente")){
            scanf("%ld",&ref);
            info_cliente(ref);
        }

        else if(!strcmp(command,"info"))
            STsort(clientes, infoCliente);

        else
            printf("ERROR: Unknown command\n");

        scanf("%s",command);
        
    }

    clientes_activos();
    cheques_por_processar();
    STfree(&clientes);

    return 0;
}
int main(int argc, char *argv[])
{
  int i, j, N = atoi(argv[1]);
  Q queues[M];
  
  srand(time(NULL));
  for (i = 0; i < M; i++)
    queues[i] = QUEUEinit(N);
  for (j = 0; j < N; j++)
    QUEUEput(queues[rand() % M], j);
  for (i = 0; i < M; i++, printf("\n"))
    for (j = 0; !QUEUEempty(queues[i]); j++)
      printf("%3d ", QUEUEget(queues[i]));
  return 0;
}
link mergesort(link t)
{
  link u;

  for (QUEUEinit(N); t != NULL; t = u)
    {
      u = t->next;
      t->next = NULL;
      QUEUEput(t);
    }
  t = QUEUEget();
  while (!QUEUEempty())
    {
      QUEUEput(t);
      t = merge(QUEUEget(), QUEUEget());
    }
  return t;
}
コード例 #10
0
ファイル: digrafo.c プロジェクト: pedropaulovc/USP-2012-1
void DIGRAPHbfsM (Digraph G, Vertex s) {
  Vertex v, w;
  cnt = 0;
  for (v = 0; v < G->V; v++)
    lbl[v] = -1;
  QUEUEinit(G->V);
  lbl[s] = cnt++;
  QUEUEput(s);
  while (!QUEUEempty()) {
    v = QUEUEget();
    for (w=0; w < G->V; w++)
      if (G->Adj[v][w] == 1 && lbl[w] == -1) {
        lbl[w] = cnt++;
        QUEUEput(w);
      }
  }
  QUEUEfree();
}
コード例 #11
0
ファイル: digrafo.c プロジェクト: pedropaulovc/USP-2012-1
void DIGRAPHbfsL (Digraph G, Vertex s) {
  Vertex v;
  link p;
  cnt = 0;
  for (v = 0; v < G->V; v++)
    lbl[v] = -1;
  QUEUEinit(G->V);
  lbl[s] = cnt++;
  QUEUEput(s);
  while (!QUEUEempty()) {
    v = QUEUEget();
    for(p=G->adj[v];p!=NULL;p=p->next)
      if (lbl[p->w] == -1) {
        lbl[p->w] = cnt++;
        QUEUEput(p->w);
      }
  }
  QUEUEfree();
}
コード例 #12
0
void traverse(int k, void(*visit)(int)) {
	link t;

	QUEUEinit();
	QUEUEput(k);
	
	while (!QUEUEempty()) {
		k = QUEUEget();
		if (visited[k] == 0) {
			(*visit)(k);
			visited[k] = 1;
			for (t = adj[k]; t != NULL; t = t->next) {
				if (visited[t->v] == 0) {
					QUEUEput(t->v);
				}
			}
		}
	}
}
コード例 #13
0
int main(void) {
	int i, t;
	
	srand(time(NULL));

	QUEUEinit(N);
	
	for (i = 0; i < N; ++i) {
		t = rand() % 100;
		QUEUEput(t);
		printf("Putting: %i\n", t);
	}
	
	for (i = 0; i < N; ++i) {
		t = QUEUEget();
		printf("Getting: %i\n", t);
	}

	return 0;
}
コード例 #14
0
ファイル: 4.19.c プロジェクト: soakiz/pinhub
 main(int argc, char *argv[])
 {
 	int i, j, N = atoi(argv[1]);
 	Q queues[M];

 	for (i = 0; i < M; i++)
 	{
 		queues[i] = QUEUEinit(N);
 	}

 	for (i = 0; i < N; i++)
 	{
 		QUEUEput(queues[rand() % M], j);
 	}

 	for (i = 0; i < N; i++)
 	{
 		for (j = 0; !QUEUEempty(queues[i]); j++)
 		{
 			printf("%3d", QUEUEget(queues[i]));
 		}
 	}
 }
コード例 #15
0
int main(void) 
{
  char *a = "E * a s * + Y *";  // E s a Y
  /* char *a = "E a * s Y + * *";  // a Y s E */
  /* char *a = "E a * s * Y + *";  // a s Y e */
  int n, i = 0;
  
  n = strlen(a);
  QUEUEinit(n);
  for (i = 0; i < n; i++)
    {
      if (isupper(a[i]))
      	QUEUEput_begin(a[i]);
      if (islower(a[i]))
      	QUEUEput_end(a[i]);
      if (a[i] == '+')
      	printf("%c ", QUEUEget_begin());
      if (a[i] == '*')
      	printf("%c ",QUEUEget_end());
    }
  printf("\n");
  return 0;
}
コード例 #16
0
ファイル: demo03.c プロジェクト: Sukumi/levawc
int main(void)
{
  /* Declare YOUR variables here ! */
  Stack mystack;
  Queue myqueue;
  int menu_choice;

  srand((unsigned int)time(NULL));

  if ((myqueue = QUEUEinit(my_destroy)) == NULL) /* Create new queue... */
    {
      printf("\nFatal error - bailing out...!");
      QUEUEdestroy(myqueue);
      exit(-1);
    }

  if ((mystack = STACKinit(my_destroy)) == NULL) /* Create new stack... */
    {
      printf("\nFatal error - bailing out...!");
      STACKdestroy(mystack);
      exit(-1);
    }

  /* Create and initialize queue and stack... */
  enqueue_push_nodes(myqueue, mystack, NR_OF_ITEMS);

  do
    {
      menu_choice = menu(MAIN_MENU_ROW, 0, 6);

      switch (menu_choice)
        {
        case 1:
          enqueue_node(myqueue);
          break;
        case 2:
          dequeue_node(myqueue);
          break;
        case 3:
          push_node(mystack);
          break;
        case 4:
          pop_node(mystack);
          break;
        case 5:
          dequeue_push_node(myqueue, mystack);
          break;
        case 6:
          print_queue_stack(myqueue, mystack);
          break;
        default:
          final_status(myqueue, mystack);
          break;
        }
    }
  while (menu_choice); 

  prompt_and_pause("\n\nLet's tidy up (destroy queue/stack)..- Bye!");

  STACKdestroy(mystack);
  QUEUEdestroy(myqueue);

  return 0;
}
コード例 #17
0
ファイル: demo3.c プロジェクト: AsamQi/levawc
int main(void)
{
  /* Declare YOUR variables here ! */
  Stack mystk;
  Queue myqueue;
  char mess[BUFSIZ];
  int i, nr;

  srand((unsigned int)time(NULL));
  my_clearscrn();

  printf("--- INITIALIZING A QUEUE, %d ELEMENTS, RANDOM INTEGER DATA ---", NR_OF_ITEMS);
  if ((myqueue = QUEUEinit(my_destroy)) == NULL) /* Initialize the queue... */
    {
      printf("\nFatal error - bailing out...!");
      exit(-1);
    }

  queue_elements(myqueue, NR_OF_ITEMS); /* Populate the queue... */

  nr = QUEUEsize(myqueue)/2;  /* Save half the size of the queue... */
  sprintf(mess, "\nNext - let's DEQUEUE %d elements from our queue...", nr);
  prompt_and_pause(mess);
  prompt_and_pause("...and now PUSH them - on a brand, new STACK...!!");

  if ((mystk = STACKinit(my_destroy)) == NULL) /* Set up a new stack... */
    {
      printf("\nFatal error - bailing out...!");
      exit(-1);
    }

  for (i = 0; i < nr; ++i)
    {
      void *piq, *pis;
      int retval;

      retval = QUEUEdequeue(myqueue, &piq);
      assert(retval == OK);

      sprintf(mess, "QUEUE: Dequeued: %02d (new frontvalue: %02d)", *(int *)piq, *(int *)QUEUEpeek(myqueue));
      prompt_and_pause(mess);

      /* Check current stack top... */
      pis = STACKpeek(mystk);
      /* Push the value just dequeued - from our queue... */
      retval = STACKpush(mystk, piq);
      assert(retval == OK);

      if (pis == NULL) /* If this is the FIRST stack push... */
	sprintf(mess, "STACK: Pushed  : %02d (old stacktop  : none)", *(int *)STACKpeek(mystk));
      else
	sprintf(mess, "STACK: Pushed  : %02d (old stacktop  : %02d)", *(int *)STACKpeek(mystk), *(int *)pis);

      /* Print the message assembled above... */
      prompt_and_pause(mess);
    }

  printf("\n--- CURRENT STATUS OF STACK AND QUEUE ---");
  printf("\nStack: ");
  SLISTtraverse(mystk, print, SLIST_FWD);
  printf("\nQueue: ");
  SLISTtraverse(myqueue, print, SLIST_FWD);
  
  prompt_and_pause("\n\nLet's tidy up (destroy queue/stack) - Bye!");

  SLISTdestroy(mystk);
  SLISTdestroy(myqueue);

  return 0;
}