Wednesday 27 March 2013

setBit CopyBits


void setBit(unsigned int& V, int bitNo, bool value){
  if(value){
    V = V | (1 << bitNo-1);
  }else{
    V = V & ~(1 << bitNo-1);
  }
}

void copyBits(unsigned int& V, int bitNo, int NoOfBits, unsigned int mask){
  unsigned int i;
  unsigned int m;
  bool value;
  for(i=bitNo; i<bitNo+NoOfBits; i++){
    m = 1 << i-1;
    value = mask & m;
    setBit(V, i, value);
  }
}

Tuesday 12 March 2013

DLL insert



void DLL::insert(int data){
  if(_head == _curr){
    _head = new Node(data, (Node*)0, _head);
    _curr->_prev = _head;
  }
  else {
    _curr->_prev = new Node(data, _curr->_prev, _curr);
    _curr->_prev->_prev->_next = _curr->_prev;
  }
}

Queue Add


void Queue::add(int data){
  Node* last = _head;
  while (last->_next) {
    last = last->_next;
  }
  Node* to_add = new Node(data);
  last->_next = to_add;
}

Probably work, probably not