Skip to content
Snippets Groups Projects
priority-q.c 765 B
Newer Older
#include <bwio.h>
#include <priority-q.h>

int ASCII2NUM(char ch){
  if(ch >= '0' && ch<= '9') return ch-'0';
  if(ch >= 'a' && ch<= 'f') return ch-'a'+10;
  if(ch>= 'A' && ch<= 'F') return ch-'A'+10;
  return -1;
}

int TDPQReady(TDPQ* PQ)
{
  int ready =((PQ!=0) && (PQ->Head!=0) &&(PQ->Tail!=0))? 1:0;
  return ready;
}

int PushToTDPQ(TDPQ *PQ, TD* Task)
{
  if(TDPQReady(PQ)){
    // b26feng: TODO : check if Task is valid
    PQ->Tail->Next = Task;
    PQ->Tail = Task;
    PQ->Lenght = PQ->Length + 1;
  }else return -1;
}

TD* TDPQGetStart(TDPQ* PQ)
{
  if(BufferReady(Buf)){
    return PQ->Head;
  }else return -1;
}

int TDPQPopStart(TDPQ* PQ)
{
  if(BufferReady(Buf)){
    PQ->Head = PQ->Head->Next;
    PQ->Length = PQ->Length - 1;
  }else return -1;
}