Example #1
0
void StringLinkedList::remove(int index) {
	if (empty()){
		throw EmptyException("Empty list");
	}
	
	if (index < 0 || index > n - 1){
		throw OutOfBoundException("Index is out of bounds");
	}

	else{
		StringNode* remove = head, *prev = head;
		int pos = 0;
		while (pos != index && remove->next != NULL){
			prev = remove;
			remove = remove->next;
			pos++;
		}
		if (index == 0){ removeFront(); }
		else if(index == n) { removeBack(); }
		else{
			prev->next = remove->next;
			delete remove;
			n--;
		}
		
	
	}
}
Example #2
0
int Place::getNbOfTokens(unsigned int color) {
	if (!isColorValid(color)) {
		throw OutOfBoundException();
	}

	return m_tokenByColor[color - 1].size();
}
Example #3
0
void StringLinkedList::insert(int index, const std::string& e) {
	if (index < 0 || index > n){
		throw OutOfBoundException("index is out of bounds");
	}
	
	else
{
		StringNode* node = head, *prev = new StringNode;
		StringNode* v = new StringNode;
		v->elem = e;
		int pos = 0;
		while (pos != index  && node-> next != NULL){
			prev = node;
			node = node->next;
			pos++;
		}
		if(index == 0) addFront(e);
		else if(index == n) addBack(e);
		else{
		prev->next = v;
		v->next = node;
		n++;
		}
	}
}
Example #4
0
InetAddress & InetAddressSet::getElementAt(long position)const throw(OutOfBoundException){
	if(position<0 || position>(size-1)){
		throw OutOfBoundException("The postion requested is NOT within the boundaries of the InetAddressSet collection");
	}
	InetAddressNode * currentNodePtr=headNodePtr;
	for(long i=0;i<position;i++){
		currentNodePtr=currentNodePtr->nextNodePtr;
	}

	return *(currentNodePtr->addrPtr);
}
Example #5
0
void TransitionBitArray::setToOne(unsigned int index)
{
	if (index >= getSize()) {
		throw OutOfBoundException();
	}

	unsigned int indexInBitArray = index / INT_SIZE;
	unsigned int indexInInt = index % INT_SIZE;

	uint16_t bitToSetAsOne = 1 << indexInInt;

	m_bitArray[indexInBitArray] = m_bitArray[indexInBitArray] | bitToSetAsOne;
}
Example #6
0
const std::string& StringLinkedList::get(int index) const {
	if (empty()){ //empty list
		throw EmptyException("Empty list");
	}
	if (index > n - 1 || index < 0){ //If the index is bigger than the size of the linked list or if the index is smaller than 0 then it is out of range
		throw OutOfBoundException("Index is Out of Bounds");
	}

	StringNode* v = head; int pos = 0; //Look for the element 
	while (pos != index){
		v = v->next;
		pos++;
	}
	return v->elem;
}
Example #7
0
TransitionBitArray::TransitionBitArray(unsigned int size)
  :m_size(size), m_maxIndexInBitArray((size - 1)/INT_SIZE), m_bitArray(NULL)
{
	if (size == 0) {
		throw OutOfBoundException();
	}

	m_bitArray = new uint16_t[m_maxIndexInBitArray + 1];

	uint16_t allBitToOne = pow(2, INT_SIZE) - 1;

	for (unsigned int i = 0; i <= m_maxIndexInBitArray; ++i) {
		m_bitArray[i] = allBitToOne;
	}

	eraseArray(); // TODO : inutile de mettre tout à un, puis un par un à zéro !!!
}
Example #8
0
InetAddress * InetAddressSet::removeElementAt(long position)throw(OutOfBoundException){
	if(position<0 || position>(size-1)){
		throw OutOfBoundException("The postion requested is NOT within the boundaries of the InetAddressSet collection");
	}
	InetAddressNode *currentNodePtr=headNodePtr;
	InetAddressNode *prevNodePtr=0;

	for(long i=0;i<position;i++){
		prevNodePtr=currentNodePtr;
		currentNodePtr=currentNodePtr->nextNodePtr;
	}


	if(prevNodePtr==0){//remove the very first element
		headNodePtr=headNodePtr->nextNodePtr;
	}else{
		prevNodePtr->nextNodePtr=currentNodePtr->nextNodePtr;
	}
	InetAddress *tmp=currentNodePtr->addrPtr;
	delete currentNodePtr;
	size--;
	return tmp;
}
Example #9
0
 wchar operator[](int idx) const
 {
     if (idx < 0 || idx >= len) throw OutOfBoundException(StringBuffer("MCString: ")+SString(idx));
     return colorer_edit_get_byte(edit, start+idx);
 }