void deleteNode(int value) 
     {
     struct node *temp = head;               
     if(head==NULL)
          printf("No Node to delete");
     else
         {
         struct node *temp;            
         if(findPosition(value)==0)
             printf("Node doesnot Exsists\n");
         else if(findPosition(value)==1 ) //Delete the first node
              {
              if(count()==1) //If there is only 1 element
                    head= NULL;
              else{                                
                  head = head->next;
                  head->prev = NULL;  }                         
              } 
         else if(findPosition(value)==count()) //Delete the last node        
              {                                            
                  root = root->prev;
                  root->next = NULL;                                                        
              }
         else   //Rest of the position
             {
             struct node *ptr=head;          
             for(int i=1;i<findPosition(value)-1;i++)          
                     ptr = ptr->next;
             ptr->next = ptr->next->next;
             ptr->next->prev = ptr;        
             }     
         }                    
     }    
예제 #2
0
int findManhattan (Board b, State goal) {
    //Not as easy!
    //Same as just difference in row + diff columns.
    //So, first get position of a point, then compare with
    //the goal position. ret = sum of cost.
    //cost(one point) = diff(row) + diff(col)
    Board g = createBoard(b->size*b->size);
    g = populateBoard(g, goal);
    
    int rowBoard, colBoard;
    int rowGoal, colGoal;
    int size = b->size;
    //HOLY MOTHER OF DERP
    int cost = 0;
    int i;

    for (i = 1; i < (b->size*b->size); i++) {
        int posBoard = findPosition(b, i);
        rowBoard = posBoard/size;
        colBoard = posBoard%size;
        int posGoal = findPosition(g,i);
        rowGoal = posGoal/size;
        colGoal = posGoal%size;
        cost += abs(rowGoal-rowBoard) + abs(colGoal-colBoard);
    }

    return cost;
}
예제 #3
0
bool HashTable<Type> :: remove(HashNode<Type> currentNode)
{
    int index = findPosition(currentNode);
    if(contains(currentNode))
    {
        int index = findPosition(currentNode);
    }
}
예제 #4
0
static BSNode* findPosition(BSNode* node, int key)
{
	if (node) {
		if (NULL == node->children[0])
			return node;
		int i = 1;
		for(; i <= node->keyNum; ++i)
			if (node->keys[i] >= key)
				return findPosition(node->children[i-1], key);
		return findPosition(node->children[i-1], key);
	}
	else
		return NULL;
}
예제 #5
0
void QualityClassification::evaluateResult()
{
	std::vector<Item> vOwnLocations;
	std::vector<Item> vRightLocations;
	readFileLocations(pathOwnLocations, vOwnLocations);
	readFileLocations(pathRightLocations, vRightLocations);

	int tp = 0, fp = 0;
	int tpShift = 0;
	float recall, precision, fMeasure;

	for(std::vector<Item>::iterator i = vOwnLocations.begin(); i != vOwnLocations.end(); i++) {
		std::vector<Item>::iterator cur = findPosition(i->name, vRightLocations);
		for(std::vector<int>::iterator k = i->medianX.begin(); k != i->medianX.end(); k++) {
			det++;
			for(std::vector<int>::iterator j = cur->medianX.begin(); j != cur->medianX.end(); j++) {
				if(isInArea(*k, *j)) {
					tp++;
				}
			}
		}
	}


	for(std::vector<Item>::iterator i = vRightLocations.begin(); i != vRightLocations.end(); i++) {
		std::vector<Item>::iterator cur = findPosition(i->name, vOwnLocations);
		if (cur != vOwnLocations.end()) {
			for(std::vector<int>::iterator k = i->medianX.begin(); k != i->medianX.end(); k++) {
				gt++;
				for(std::vector<int>::iterator j = cur->medianX.begin(); j != cur->medianX.end(); j++) {
					if(isInArea(*j, *k)) {
						tpShift++;
						break;
					}
				}
			}
		} else {
			gt++;
		}
	}

	fp = det - tp;
	recall = (double) tpShift / gt;
	precision = (double) tp / det;
	fMeasure = 2 * recall * precision / ( recall + precision);
	printf ("\n\nrecall: %.5f%% (tp':%d. gt:%d)\n", recall * 100, tpShift, gt);
	printf ("precision: %.5f%% (tp:%d. fp:%d. det:%d)\n", precision * 100, tp, fp, det);
	printf ("F: %.5f%%\n", 100 * fMeasure);
}
예제 #6
0
int isLegal (Board b, int direction) {
    int ret = TRUE;
    //What are the illegal cases? Moving outside arrays, obviously.
    int position, row, column;
    position = findPosition(b, BLANK);
    row = position/b->size;
    column = position%b->size;
    if (direction == UP) {
        if (row == 0) {
            ret = FALSE;
        }
    } else if (direction == DOWN) {
        if (row == (b->size - 1)) {
            ret = FALSE;
        } 
    } else if (direction == LEFT) {
        if (column == 0) {
            ret = FALSE;
        }
    } else if (direction == RIGHT) {
        if (column == (b->size - 1)) {
            ret = FALSE;
        }
    }
    if (ret == FALSE) {
        fprintf(stderr, "Error: Illegal move!\n");
    }
    return ret;
}
예제 #7
0
int *
nextGreaterElement(int *findNums, int findNumsSize,
                   int *nums, int numsSize, int *returnSize)
{
    int *result;

    result = (int *) malloc(sizeof(int) * findNumsSize);
    *returnSize = findNumsSize;

    for (int i = 0; i < findNumsSize; i++) {
        int pos = findPosition(nums, numsSize, findNums[i]);

        int ans = -1;
        for (int j = pos; j < numsSize; j++) {
            if (nums[j] > findNums[i]) {
                ans = nums[j];
                break;
            }
        }

        result[i] = ans;
    }

    return result;
}
예제 #8
0
int main()
{
    #define arraysize 5
    int array[arraysize]={0};
    int i,elementsize=1,position,j,element;
    
    printf("请输入5个整数:\n");
    scanf("%d",&array[0]);
    
    for(i=0;i<arraysize;i++)
    {
                            scanf("%d",&element);
                            position=findPosition(array,arraysize,elementsize,element);
                             
                            j=insertElement(array,arraysize,elementsize,position,element);
                            //加[]有问题
                            elementsize++;
                            
                            if(j==1)
                            {
                                    printf("\n成功插入\n");
                            }
                            
                            if(elementsize==5)
                            {
                                    printf("\n成功插入\n");
                            }   
    }
    for(i=0;i<arraysize;i++)
    {
                            printf("%d\t",array[i]);
    }
}
예제 #9
0
nsresult txNodeSet::add(const txXPathNode& aNode)
{
    NS_ASSERTION(mDirection == kForward,
                 "only append(aNode) is supported on reversed nodesets");

    if (isEmpty()) {
        return append(aNode);
    }

    PRBool dupe;
    txXPathNode* pos = findPosition(aNode, mStart, mEnd, dupe);

    if (dupe) {
        return NS_OK;
    }

    // save pos, ensureGrowSize messes with the pointers
    PRInt32 moveSize = mEnd - pos;
    PRInt32 offset = pos - mStart;
    if (!ensureGrowSize(1)) {
        return NS_ERROR_OUT_OF_MEMORY;
    }
    // set pos to where it was
    pos = mStart + offset;

    if (moveSize > 0) {
        LOG_CHUNK_MOVE(pos, pos + 1, moveSize);
        memmove(pos + 1, pos, moveSize * sizeof(txXPathNode));
    }

    new(pos) txXPathNode(aNode);
    ++mEnd;

    return NS_OK;
}
예제 #10
0
void CTECHashTable<Type>::add(HashNode<Type> currentNode)
{
	if (!contains(currentNode))
	{
		//Update size if needed. Find where to put the value.
		if (this->size / this->capacity >= this->efficiencyPercentage)
		{
			updateSize();
		}

		int positionToInsert = findPosition(currentNode);

		if (internalStorage[positionToInsert] != nullptr)
		{
			//Loop over the internalStorage to find the next empty slot. Insert the value there.
			while(internalStorage[positionToInsert] != nullptr)
			{
				//positionToInsert = (positionToInsert + 1) % capacity;
				positionToInsert = handleCollision(currentNode);
			}
		}
		internalStorage[positionToInsert] = &currentNode;
		size++;
	}
}
예제 #11
0
void HashTable<Type> :: updateTableCapacity()
{
    int updatedCapacity = getNextPrime();
    CTECList<HashNode<Type>> * updateTable = new CTECList<HashNode<Type>> [updatedCapacity];
    
    int oldTableCapacity = tableCapacity;
    tableCapacity = updatedCapacity;
    
    for(int index = 0; index < oldTableCapacity; index++)
    {
        if (tableStorage[index] != nullptr)
        {
            CTECList<HashNode<Type>> temp = tableStorage[index];
            for(int innerIndex = 0; innerIndex < temp.getSize(); innerIndex++)
            {
                int updatedTablePosition = findPosition(temp.get(index));
                if(updateTable[updatedTablePosition] == nullptr)
                {
                    CTECList<HashTable<Type>> updatedList;
                    updatedList.addEnd(temp.get(index));
                }
                else
                {
                    updateTable[updatedTablePosition].addEnd(temp.get(index));
                }
                
            }
        }
    }
        
}
예제 #12
0
파일: main2.c 프로젝트: ohayak/tars_code
void homologation(void)
{
	disableSpinning();
	findPosition(team);
	trajectory_goto_d(&traj, END, 18);
	if(team == RED)
	{
		trajectory_goto_a(&traj, END, 45);      	     
	}
	else
	{
		trajectory_goto_a(&traj, END, -45);	
	}
	while(!trajectory_is_ended(&traj));

	enableSpinning();


	asserv_set_vitesse_normal(&asserv);

	while(TIRETTE);
	avoidance_init();
	if(team == RED)
	{
		returnFire(Y1);
	}
	else
	{
		returnFire(R1);
	}		
}
예제 #13
0
Board makeMove (Board b, int direction) {
    int position;
    int row;
    int column;
    position = findPosition(b, BLANK);
    row = position/b->size;
    column = position%b->size;
    if (isLegal(b,direction)) {
        if (direction == UP) {
            //Swap positions with position - size
            int temp;
            temp = b->board[row][column];
            b->board[row][column] = b->board[row - 1][column];
            b->board[row-1][column] = temp;
        } else if (direction == DOWN) {
            int temp;
            temp = b->board[row][column];
            b->board[row][column] = b->board[row + 1][column];
            b->board[row+1][column] = temp;
        } else if (direction == LEFT) {
            int temp;
            temp = b->board[row][column];
            b->board[row][column] = b->board[row][column - 1];
            b->board[row][column - 1] = temp;
        } else if (direction == RIGHT) {
            int temp;
            temp = b->board[row][column];
            b->board[row][column] = b->board[row][column + 1];
            b->board[row][column + 1] = temp;
        }
    }
    return b;
}
int CTECHashTable<Type> :: handleCollision(HashNode<Type> currentNode){
	int updatedPosition = findPosition(currentNode);

	updatedPosition  =(47 +(updatedPosition * updatedPosition))%capacity;

	return updatedPosition;
}
예제 #15
0
int HashTable<Type> :: handleCollision(HashNode<Type> currentNode)
{
    int reHashedPosition = findPosition(currentNode);
    int random = rand();
    reHashedPosition = random + (reHashedPosition * reHashedPosition) % capacity;
    
    return reHashedPosition;
}
//======================================================================================================================
bool isStable(const std::vector<Item>& before, const std::vector<Item>& after)
{
    for (size_t i = 0; i < after.size() - 1; i++)
    {
        if (after[i].getKey() == after[i+1].getKey())
        {
            int beforeDistance = findPosition(before, after[i]) - findPosition(before, after[i+1]);
            int afterDistance  = findPosition(after, after[i])  - findPosition(after, after[i+1]);

            if (sign(beforeDistance) != sign(afterDistance))
            {
                return false;
            }
        }
    }

    return true;
}
예제 #17
0
int CTECHashTable<Type> :: handleCollision(HashNode<Type> currentNode)
{
	int reHashedPosition = findPosition(currentNode);
	int randomEven = rand() % capacity;

	reHashedPosition = (randomEven + (reHashedPosition * reHashedPosition)) % capacity;

	return reHashedPosition;
}
/*
 * fill: Fills the histogram according to a set of values
 * @param values: Array with the variable values
 * @return: True if the histo is filled, False otherwise
 */
bool histoN::fill(Double_t* values){
	Int_t pos = findPosition(values);
	if (pos == -1) return false;
	else{
		histo[pos] += 1;
		entries ++;
		return true;
	}
}
예제 #19
0
void MAPSPredictor::predecir()
{
	if (abs((float)(timestamp - min(LaserObjects[1].timestamp, CameraObjects[1].timestamp)) > framerate * 10))
	{
		timestamp = min(LaserObjects[1].timestamp, CameraObjects[1].timestamp);
	}
	while (timestamp < max(LaserObjects[1].timestamp, CameraObjects[1].timestamp))
	{
		timestamp += framerate;
	}
	//Predict the position of the obstacles
	if (updated[0]) 
	{
		LaserObjectsOutput = LaserObjects[1];
		for (size_t i = 0; i < LaserObjectsOutput.number_of_objects; i++)
		{
			int pos = findPosition(LaserObjects[0],LaserObjectsOutput.object[i].id);
			if (pos != -1)
			{
				//Move the obstacle
				moveObstacle(&LaserObjectsOutput.object[i], LaserObjectsOutput.timestamp);
			}
		}
		
		updated[0] = false;
	}
	if (updated[1])
	{
		CameraObjectsOutput = CameraObjects[1];
		for (size_t i = 0; i < CameraObjectsOutput.number_of_objects; i++)
		{
			int pos = findPosition(CameraObjects[0], CameraObjectsOutput.object[i].id);
			if (pos != -1)
			{
				//Move the obstacle
				moveObstacle(&CameraObjectsOutput.object[i], CameraObjectsOutput.timestamp);
			}
		}

		updated[1] = false;
	}
	predicted = true;	
}
예제 #20
0
// Driver program to test above function
int main(void)
{
    int n = 0;
    int pos = findPosition(n);
    (pos == -1)? printf("n = %d, Invalid number\n", n):
                 printf("n = %d, Position %d \n", n, pos);
 
    n = 12;
    pos = findPosition(n);
    (pos == -1)? printf("n = %d, Invalid number\n", n):
                 printf("n = %d, Position %d \n", n, pos);
 
    n = 128;
    pos = findPosition(n);
    (pos == -1)? printf("n = %d, Invalid number\n", n):
                 printf("n = %d, Position %d \n", n, pos);
 
    return 0;
}
예제 #21
0
파일: Keyboard.c 프로젝트: rafik991/Uklady
int getKeyNumber(){
	int i=0;
	PORTC = 0x00;
	DDRC = 0x0F; // output dla czesci wierszy
	PORTC = 0xF0;
	int wiersz  = findPosition((PORTC & 0xF0));
	for(i=0;i<8;i++){
		
	}
	PINC = 0;
	PORTC = 0x00;
	DDRC = 0xF0; //output dla czesci kolumnowej
	PORTC =	0x0F;
	for(i=0;i<8;i++){
		
	}
	int kolumna = findPosition((PORTC & 0x0F));
	int liczba = (wiersz * 4) + kolumna;
	return liczba; 
}
void test(int noOfTestCases){

	int count;
	for (count = 0; count < noOfTestCases; ++count){

		if (findPosition(tests[count].nValues, tests[count].length, tests[count].r) == tests[count].result)
			printf("\nPASS");
		else
			printf("\nFAIL");
	}
}
예제 #23
0
void insertNode(BSTree* tree, int key, void* value)
{
	BSNode* node = findPosition(tree->root, key);
	if (node) {
		_updateNode(tree, node, key, value);
	}
	else {
		node = initNode(tree->mOrder, key, value);
		tree->root = node;
	}
}
예제 #24
0
void KSPlanetBase::updateCoords( KSNumbers *num, bool includePlanets, const dms *lat, const dms *LST ){
	if ( includePlanets ) {
		data->earth()->findPosition( num ); //since we don't pass lat & LST, localizeCoords will be skipped

		if ( lat && LST ) {
			findPosition( num, lat, LST, data->earth() );
			if ( hasTrail() ) Trail.removeLast();
		} else {
			findGeocentricPosition( num, data->earth() );
		}
	}
}
int quadraticProbe(WordHashTable *wht, void *data)
{
   int offset = 1;
   int current = findPosition(wht->allocated, data);
   
   while (wht->entries[current] && wht->entries[current] != data) {
      current += offset;
      offset += 2;
      current %= wht->allocated;
   }
   return current;
}
예제 #26
0
txXPathNode*
txNodeSet::findPosition(const txXPathNode& aNode, txXPathNode* aFirst,
                        txXPathNode* aLast, PRBool& aDupe) const
{
    aDupe = PR_FALSE;
    if (aLast - aFirst <= 2) {
        // If we search 2 nodes or less there is no point in further divides
        txXPathNode* pos = aFirst;
        for (; pos < aLast; ++pos) {
            PRIntn cmp = txXPathNodeUtils::comparePosition(aNode, *pos);
            if (cmp < 0) {
                return pos;
            }

            if (cmp == 0) {
                aDupe = PR_TRUE;

                return pos;
            }
        }
        return pos;
    }

    // (cannot add two pointers)
    txXPathNode* midpos = aFirst + (aLast - aFirst) / 2;
    PRIntn cmp = txXPathNodeUtils::comparePosition(aNode, *midpos);
    if (cmp == 0) {
        aDupe = PR_TRUE;

        return midpos;
    }

    if (cmp > 0) {
        return findPosition(aNode, midpos + 1, aLast, aDupe);
    }

    // midpos excluded as end of range

    return findPosition(aNode, aFirst, midpos, aDupe);
}
예제 #27
0
void portfolio::split(pTrade input){
  //  cout << "Enter split" << endl;

  // Find the index of the desired position exists
  int index = findPosition(input.symbol);

  if(index == -1)    // Error message if the desired position does not exist
    cout << "Error: failed to find position: " << input.symbol << endl;
  else
    (*active[index]).split(input);

  // cout << "Exit split" << endl;
}
예제 #28
0
void portfolio::spinoff(pTrade input){
  //  cout << "Enter spinoff";

  // Find the index of the desired position exists
  int index = findPosition(input.sortID);

  if(index == -1)
    cout << "Error: failed to find position: " << input.symbol << endl;
  else
    active.push_back((*active[index]).spinoff(input));

  //  cout << "Exit spinoff";
}
예제 #29
0
void portfolio::dividend(pTrade input){
  int index = findPosition(input.symbol);
  
  //Find the position in the portfolio, 
  //then adds the dividend to that positions;

  if(index == -1){
    index = findInactivePosition(input.symbol);

    (*inactive[index]).xdividend(input);
  }
  else
    (*active[index]).dividend(input);
}
bool CTECHashTable<Type>:: contains(HashNode<Type> currentNode){
	bool isInTable = false;

	int possibleLocation = findPosition(currentNode);

	while(internalStorage[possibleLocation] != nullptr && !isInTable){
		if(internalStorage[possibleLocation] == currentNode.getValue()){
			isInTable = true;
		}
		possibleLocation = (possibleLocation + 1) % capacity;
	}

	return isInTable;
}