Ejemplo n.º 1
0
void Q3GList::inSort( Q3PtrCollection::Item d )
{
    int index = 0;
    register Q3LNode *n = firstNode;
    while ( n && compareItems(n->data,d) < 0 ){ // find position in list
	n = n->next;
	index++;
    }
    insertAt( index, d );
}
Ejemplo n.º 2
0
void VGradientEx::inSort( VColorStopEx* d )
{
	int index = 0;
	register VColorStopEx *n = m_colorStops.value(index);
	while (n && compareItems(n,d) <= 0)
	{
		n = m_colorStops.value(index);
		++index;
	}
	m_colorStops.insert( qMin(index, m_colorStops.size()), d );
}
Ejemplo n.º 3
0
void VGradient::inSort( VColorStop* d )
{
	int index = 0;
	VColorStop *n = m_colorStops.value(index);
	while (n && compareItems(n,d) <= 0)
	{
		++index;
		n = m_colorStops.value(index);
	}
	m_colorStops.insert( qMin(index, m_colorStops.size()), d );
}
Ejemplo n.º 4
0
int CoreAttributesList::inSort(CoreAttributes* attr)
{
    int i = 0;
    for (; i < count(); ++i) {
        int r = compareItems(attr, at(i));
        if (r < 0) {
            break;
        }
    }
    insert(i, attr);
    return i;
}
Ejemplo n.º 5
0
void Q3GList::heapSortPushDown( Q3PtrCollection::Item* heap, int first, int last )
{
    int r = first;
    while( r <= last/2 ) {
	// Node r has only one child ?
	if ( last == 2*r ) {
	    // Need for swapping ?
	    if ( compareItems( heap[r], heap[ 2*r ] ) > 0 ) {
		Q3PtrCollection::Item tmp = heap[r];
		heap[ r ] = heap[ 2*r ];
		heap[ 2*r ] = tmp;
	    }
	    // That's it ...
	    r = last;
	} else {
	    // Node has two children
	    if ( compareItems( heap[r], heap[ 2*r ] ) > 0 &&
		 compareItems( heap[ 2*r ], heap[ 2*r+1 ] ) <= 0 ) {
		// Swap with left child
		Q3PtrCollection::Item tmp = heap[r];
		heap[ r ] = heap[ 2*r ];
		heap[ 2*r ] = tmp;
		r *= 2;
	    } else if ( compareItems( heap[r], heap[ 2*r+1 ] ) > 0 &&
			compareItems( heap[ 2*r+1 ], heap[ 2*r ] ) < 0 ) {
		// Swap with right child
		Q3PtrCollection::Item tmp = heap[r];
		heap[ r ] = heap[ 2*r+1 ];
		heap[ 2*r+1 ] = tmp;
		r = 2*r+1;
	    } else {
		// We are done
		r = last;
	    }
	}
    }
}
Ejemplo n.º 6
0
int Q3GList::find( Q3PtrCollection::Item d, bool fromStart )
{
    register Q3LNode *n;
    int	     index;
    if ( fromStart ) {				// start from first node
	n = firstNode;
	index = 0;
    } else {					// start from current node
	n = curNode;
	index = curIndex;
    }
    while ( n && compareItems(n->data,d) ){	// find equal match
	n = n->next;
	index++;
    }
    curNode = n;
    curIndex = n ? index : -1;
    return curIndex;				// return position of item
}
Ejemplo n.º 7
0
void Q3GList::sort()
{
    uint n = count();
    if ( n < 2 )
	return;

    // Create the heap
    Q3PtrCollection::Item* realheap = new Q3PtrCollection::Item[ n ];
    // Wow, what a fake. But I want the heap to be indexed as 1...n
    Q3PtrCollection::Item* heap = realheap - 1;
    int size = 0;
    Q3LNode* insert = firstNode;
    for( ; insert != 0; insert = insert->next ) {
	heap[++size] = insert->data;
	int i = size;
	while( i > 1 && compareItems( heap[i], heap[ i / 2 ] ) < 0 ) {
	    Q3PtrCollection::Item tmp = heap[ i ];
	    heap[ i ] = heap[ i/2 ];
	    heap[ i/2 ] = tmp;
	    i /= 2;
	}
    }

    insert = firstNode;
    // Now do the sorting
    for ( int i = n; i > 0; i-- ) {
	insert->data = heap[1];
	insert = insert->next;
	if ( i > 1 ) {
	    heap[1] = heap[i];
	    heapSortPushDown( heap, 1, i - 1 );
	}
    }

    delete [] realheap;
}