예제 #1
0
파일: BST.cpp 프로젝트: haydenx83/School
//traverse list inorder and add elements to the array
int BST::sortHelper(TreeItemType a[], int i, TreeNode* t)
{
	TreeNode* curr = t;
        TreeItemType x;

        if(t->leftChildPtr != NULL)
        {
            curr = curr->leftChildPtr;
            sortHelper(a,i,curr);
        }

        x = curr->item;
        a[i] = x;
	i++;

        if(t->rightChildPtr != NULL)
        {
            curr = curr->rightChildPtr;
            sortHelper(a,i,curr);
        }
	if(i == (size() - 1))
	{
	    int j,k;
	    deleteTree(root);
	    j = sizeof(a);
	    k = ceil(j/2);

		buildHelper(a,k,0,j-1,root);
	}
}
예제 #2
0
파일: BST.cpp 프로젝트: elisemmc/EECS268
//traverse list inorder and add elements to the array 
int BST::sortHelper(TreeItemType a[], int& i, TreeNode* t) const
{
//TODO:
  if(t==NULL){
    return 0;
  }
  else{
    sortHelper(a, i, t->leftChildPtr);
    a[i]=t->item;
    i++;
    sortHelper(a, i, t->rightChildPtr);
    return 1;
  }
}
예제 #3
0
void DeckListModel::sortHelper(InnerDecklistNode *node, Qt::SortOrder order)
{
    // Sort children of node and save the information needed to
    // update the list of persistent indexes.
    QVector<QPair<int, int> > sortResult = node->sort(order);
    
    QModelIndexList from, to;
    int columns = columnCount();
    for (int i = sortResult.size() - 1; i >= 0; --i) {
        const int fromRow = sortResult[i].first;
        const int toRow = sortResult[i].second;
        AbstractDecklistNode *temp = node->at(toRow);
        for (int j = 0; j < columns; ++j) {
            from << createIndex(fromRow, j, temp);
            to << createIndex(toRow, j, temp);
        }
    }
    changePersistentIndexList(from, to);

    // Recursion
    for (int i = node->size() - 1; i >= 0; --i) {
        InnerDecklistNode *subNode = dynamic_cast<InnerDecklistNode *>(node->at(i));
        if (subNode)
            sortHelper(subNode, order);
    }
}
예제 #4
0
void DeckListModel::sort(int column, Qt::SortOrder order)
{
    lastKnownColumn = column;
    lastKnownOrder = order;

    emit layoutAboutToBeChanged();
    DeckSortMethod sortMethod;
    switch(column) {
    case 0:
        sortMethod = ByNumber;
        break;
    case 1:
        sortMethod = ByName;
        break;
    case 2:
        sortMethod = ByPrice;
        break;
    default:
        sortMethod = ByName;
    }
    root->setSortMethod(sortMethod);
    sortHelper(root, order);
    emit layoutChanged();
}
예제 #5
0
void DeckListModel::sort(int /*column*/, Qt::SortOrder order)
{
	emit layoutAboutToBeChanged();
	sortHelper(root, order);
	emit layoutChanged();
}
예제 #6
0
파일: BST.cpp 프로젝트: elisemmc/EECS268
//calls sortHelper
void BST::sort(TreeItemType a[]) const
{
//TODO: Must Implement
  int i = 0;
  sortHelper(a, i, root); 
}
예제 #7
0
파일: BST.cpp 프로젝트: haydenx83/School
//calls sortHelper
void BST::sort(TreeItemType a[])
{
    int count = 0;
	sortHelper(a,count,root);
}