Exemplo n.º 1
0
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);
 }
}
Exemplo n.º 2
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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
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();
}
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;
}
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);
				}
			}
		}
	}
}
Exemplo n.º 9
0
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();
}
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;
}
Exemplo n.º 11
0
void adiciona_cheque_por_processar(int valor, long refe, long refb, long refc){
    
    ChequeObj n_cheque; /*Cria um objeto cheque*/
    n_cheque = (ChequeObj)malloc(sizeof(struct cheque));
    
    n_cheque->valor = valor;
    n_cheque->refe = refe;
    n_cheque->refb = refb;
    n_cheque->refc = refc;
    
    QUEUEput(n_cheque); /*Insere-se um novo cheque na queue dos cheques*/
}
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;
}
Exemplo n.º 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;
}
Exemplo n.º 14
0
Arquivo: 4.19.c Projeto: 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]));
 		}
 	}
 }
Exemplo n.º 15
0
void adiciona_cheque(int valor,long int refe,long int refb,long int refc)
{
    Cliente emp, rec;
    Cheque a;
    a = criaCheque(valor,refe,refb,refc);

    QUEUEput(cheques, a);
    if (STsearch(clientes, refe) != NULL) {
        emp = (STsearch(clientes, refe));
        emp -> val_emi += valor;
        emp -> num_emi += 1;
    }
    else
        STinsert(&clientes, criaCliente(refe,1,valor,0,0));

    if (STsearch(clientes, refb) != NULL) {
        rec = (STsearch(clientes, refb)); 
        rec -> val_rec += valor;
        rec -> num_rec += 1;
    }
    else
        STinsert(&clientes, criaCliente(refb,0,0,1,valor));
}