Exemple #1
0
void *Q_PopTail(queue *q)
{
      datanode    *p;
      void        *d;

      if (Q_Empty(q))
            return NULL;

      d = q->tail->data;
      p = q->tail->prev;
      free(q->tail);
      q->size--;

      if (q->size == 0)
            q->head = q->tail = q->cursor = NULL;
      else
      {
            q->tail = (node *)p;
            q->tail->next = NULL;
            q->cursor = q->tail;
      }

      q->sorted = False_;

      return d;
}
Exemple #2
0
void *Q_PopHead(queue *q)
{
      datanode    *n;
      void        *d;

      if (Q_Empty(q))
            return NULL;

      d = q->head->data;
      n = q->head->next;
      free(q->head);

      q->size--;

      if (q->size == 0)
            q->head = q->tail = q->cursor = NULL;
      else
      {
            q->head = (node *)n;
            q->head->prev = NULL;
            q->cursor = q->head;
      }

      q->sorted = False_;

      return d;
}
Exemple #3
0
int bfs(int source, int dest){

    int u, v;
    int d[300+10] , visited[300+10];
    for(int i=0;i<305;i++) {d[i] = 10000; visited[i] = 0;}


    d[source] = 0;
    parent[source] = -1;
    visited[source] = 1;
    EnQ(source);

    while(Q_Empty()==0){

        u = DeQ();

        for(v=1; v<=Total_Router; v++){

            if(routing_table[u][v]==1&&visited[v]==0){
                d[v] = d[u] + 1;
                visited[v] = 1;
                parent[v] = u;
                EnQ(v);
            }

        }
    }
    return d[dest];
}
Exemple #4
0
void *Q_Last( queue *q )
{
    if ( Q_Empty( q ) ) return NULL;

    q->cursor = q->tail;

    return q->cursor->data;
}
Exemple #5
0
void *Q_First( queue *q )
{
    if ( Q_Empty( q ) ) return NULL;

    q->cursor = q->head;

    return q->cursor->data;
}