void nsFileView::SortInternal() { SortArray(mDirList); SortArray(mFilteredFiles); if (mReverseSort) { ReverseArray(mDirList); ReverseArray(mFilteredFiles); } }
NS_IMETHODIMP nsFileView::SetShowOnlyDirectories(bool aOnlyDirs) { if (aOnlyDirs == mDirectoryFilter) return NS_OK; mDirectoryFilter = aOnlyDirs; PRUint32 dirCount; mDirList->Count(&dirCount); if (mDirectoryFilter) { PRInt32 rowDiff = mTotalRows - dirCount; mFilteredFiles->Clear(); mTotalRows = dirCount; if (mTree) mTree->RowCountChanged(mTotalRows, -rowDiff); } else { // Run the filter again to get the file list back FilterFiles(); SortArray(mFilteredFiles); if (mReverseSort) ReverseArray(mFilteredFiles); if (mTree) mTree->RowCountChanged(dirCount, mTotalRows - dirCount); } return NS_OK; }
/* -------------------------------------------------------------------- * FUNCTION NAME: Draw * DESCRIPTION : Draws Combobox on console, will check whether to draw * One label or the entire combobox using _isOpen. * RETURN : None. * NOTES : Polymorphic function - inherited from Widget. * -------------------------------------------------------------------- */ void ComboBox::Draw(COORD CursorPosition, const HANDLE& console) { if (!_comboNames.size()) return; if (!_isSorted) { SortArray(); } strVecItr itr = _comboNames.begin(); if (!_isOpen) { _isOpen = true; CursorPosition = GetCoord(); clearWidget(CursorPosition, console, GetLongestString() + 6, _comboNames.size()*HEIGHT_OF_CELL); while (itr->index != _selected) itr++; DrawItem(CursorPosition, console, itr, true); } else { while (itr != _comboNames.end()) { _isOpen = false; if (itr->index == _selected) DrawItem(CursorPosition, console, itr, true); else DrawItem(CursorPosition, console, itr, false); CursorPosition.Y += 2; ++itr; } } }
/* -------------------------------------------------------------------- * FUNCTION NAME: Delete * DESCRIPTION : Delets a label from the ComboBox object searching a string. * RETURN : None. * NOTES : None. * -------------------------------------------------------------------- */ void ComboBox::Delete(const std::string& toDelete) { for (strVecItr itr = _comboNames.begin(); itr != _comboNames.end(); ++itr) { if (itr->text == toDelete) { _comboNames.erase(itr); SortArray(); if (_current != 0) --_current; return; } } }
int main() { int n, i; unsigned char *ar; printf("Enter the number: "); scanf("%d", &n); ar = (unsigned char *)malloc(sizeof(unsigned char)*n); for (i = 0; i<n; i++) { printf("Enter next element of array: "); scanf("%hhu", &ar[i]); } SortArray(n, ar); for (i = 0; i<n; i++) printf("%hhu ", ar[i]); free(ar); return 0; }
// /// Add the strings into the listbox. // void TCheckList::SetupWindow() { TRACEX(OwlControl, 1, "TCheckList::SetupWindow() @" << (void*)this); // Call the base class // TListBox::SetupWindow(); // if sorted ListBox if ((GetStyle() & LBS_SORT)){ if(Items.Size()) SortArray(&Items[0],Items.Size()); for (uint i = 0; i < Items.Size(); i++) InsertString((LPCTSTR)Items[i], i); } else{ for (uint i = 0; i < Items.Size(); i++) AddString((LPCTSTR)Items[i]); } }
NS_IMETHODIMP nsFileView::SetFilter(const nsAString& aFilterString) { PRUint32 filterCount = mCurrentFilters.Length(); for (PRUint32 i = 0; i < filterCount; ++i) NS_Free(mCurrentFilters[i]); mCurrentFilters.Clear(); nsAString::const_iterator start, iter, end; aFilterString.BeginReading(iter); aFilterString.EndReading(end); while (true) { // skip over delimiters while (iter != end && (*iter == ';' || *iter == ' ')) ++iter; if (iter == end) break; start = iter; // start of a filter // we know this is neither ';' nor ' ', skip to next char ++iter; // find next delimiter or end of string while (iter != end && (*iter != ';' && *iter != ' ')) ++iter; PRUnichar* filter = ToNewUnicode(Substring(start, iter)); if (!filter) return NS_ERROR_OUT_OF_MEMORY; if (!mCurrentFilters.AppendElement(filter)) { NS_Free(filter); return NS_ERROR_OUT_OF_MEMORY; } if (iter == end) break; ++iter; // we know this is either ';' or ' ', skip to next char } if (mTree) { mTree->BeginUpdateBatch(); PRUint32 count; mDirList->Count(&count); mTree->RowCountChanged(count, count - mTotalRows); } mFilteredFiles->Clear(); FilterFiles(); SortArray(mFilteredFiles); if (mReverseSort) ReverseArray(mFilteredFiles); if (mTree) mTree->EndUpdateBatch(); return NS_OK; }
int NumstatI(int argc, char **argv) { NUMSTAT *nsPO; int num; DOUB *rvalsPD; nsPO = CreateNumstatPO(); if(!ParseArgsI(argc,argv, "S -sl B -his D2 -echo S -efi B -col I -out S -hlr D2\ -sk B -ic I -hp B -pi B -hb D -prs D\ -prl S -hmb I -hwd I -hne B -scol I -sp B -hntb B -htxf D -dif B", nsPO->inname, &nsPO->do_sl, &nsPO->h_bin,&nsPO->h_lo, nsPO->echo, &nsPO->do_efi, &nsPO->col, nsPO->outname, &nsPO->h_lo,&nsPO->h_hi, &nsPO->do_sk, &nsPO->do_ic, &nsPO->do_hplot, &nsPO->do_ploti, &nsPO->h_bin, &nsPO->prsd, nsPO->prls, &nsPO->h_maxbin, &nsPO->h_pwide, &nsPO->do_hends, &nsPO->scol, &nsPO->do_splot, &nsPO->do_hntb, &nsPO->htb_xfold, &nsPO->do_dif, (int *)NULL)) { NumstatUse(); CHECK_NUMSTAT(nsPO); return(TRUE); } /*** * Arg consistency check */ if(!CheckNumstatOptionsI(nsPO)) { CHECK_NUMSTAT(nsPO); return(FALSE); } /*** * Files */ if(!OpenNumstatFilesI(nsPO)) { CHECK_NUMSTAT(nsPO); return(FALSE); } /***** * Load data lines */ if(!LoadColValsFromFileI(nsPO)) { CHECK_NUMSTAT(nsPO); return(FALSE); } if(!nsPO->do_sl) { fprintf(nsPO->out,"%s# %d lines read from %s, %d values\n", nsPO->echo, nsPO->lines,nsPO->inname,nsPO->num); fprintf(nsPO->out,"%s# (column %d)\n",nsPO->echo, nsPO->col); } /*** * Doing difference? Set these values */ if(nsPO->do_dif) { CalcColDifsI(nsPO); } /*** * Get pointer to raw double array and length. * This is easier to use with array functions; Also sort for percentile */ GetNumlistPtrDoubsI(nsPO->vals, &rvalsPD, &num); /*** * Call to get stats * If only single-line output and not percentiles, report and bail here */ NumlistStatsI(nsPO->vals, -1, -1, &nsPO->min,&nsPO->max,&nsPO->av,&nsPO->sd); NumlistSumI(nsPO->vals, -1, -1, &nsPO->sum); if( (nsPO->do_sl) && (!nsPO->do_perc) ) { NumstatOneLineOut(nsPO); CHECK_NUMSTAT(nsPO); return(TRUE); } /*** * Automatic histogram best binning (report even if no hist) */ HandleHisMaxBinsI(nsPO); NumlistNaturalHistBinI(nsPO->vals, nsPO->h_maxbin, TRUE, &nsPO->h_abin, &nsPO->h_alo, &nsPO->h_ahi); /*** * Header story */ if( !nsPO->do_sl ) { NumstatHandleHeader(nsPO); } /*** * Percentile shams? */ if(nsPO->do_perc) { SortArray(rvalsPD,IS_DOUB,num,SORT_ASCEND); if(!NO_S(nsPO->prls)) { HandleListPercentiles(nsPO, rvalsPD, num, nsPO->out); } if(!BAD_DOUB(nsPO->prsd)) { HandleStepPercentiles(nsPO, rvalsPD, num, nsPO->out); } } /*** * Doing histogram? */ if(nsPO->do_hist) { NumstatHandleHistI(nsPO); } if(nsPO->do_splot) { NumstatHandleSplotI(nsPO); } CHECK_NUMSTAT(nsPO); return(TRUE); }
/*************************************************************************** ** ReadSites -- ** This function asks the user for the name of the data ** file to be used, opens it, reads the website Addresses and ** sorts them. The totals are then computed and the tables printed using ** other functions within this one. ** Inputs: None ** Outputs: 4 arrays fll of websites and printed results. ***************************************************************************/ void ReadSites() { FILE *ifp; char filename[SIZE] = "cat"; char temp[SIZE] = "dog"; int j = 0; /*The four arrays are declared*/ WEBSITE t, comSites[SIZE], govSites[SIZE], eduSites[SIZE], netSites[SIZE]; int TotalNonUniqueSites = 0, TotalUniqueSites = 0, TotalTimeLogged = 0; int TotalFunSites = 0, TotalSearchSites = 0, TotalEducationSites = 0; int TotalNewsSites = 0, *pTotalNewsSites, *pTotalNonUniqueSites; int *pTotalUniqueSites, *pTotalTimeLogged, *pTotalFunSites; int *pTotalSearchSites, *pTotalEducationSites; /*The pointers are set to point to the their corresponding values*/ pTotalNonUniqueSites = &TotalNonUniqueSites; pTotalUniqueSites = &TotalUniqueSites; pTotalTimeLogged = &TotalTimeLogged; pTotalFunSites = &TotalFunSites; pTotalSearchSites = &TotalSearchSites; pTotalEducationSites = &TotalEducationSites; pTotalNewsSites = &TotalNewsSites; /*The are filled with dummy values*/ FillArray(comSites); FillArray(netSites); FillArray(eduSites); FillArray(govSites); /*Asks the user for the file name*/ fprintf(stdout, "\nPlease enter the file name: "); fscanf(stdin, "%s", filename); ifp = fopen(filename, "r"); /*If the file cannot exit and give error message*/ if(ifp == NULL) { fprintf(stderr, "The file could not be opened."); exit(-1); } /*Scans every thing in the file until it reaches the end*/ while(fscanf(ifp, "%s %s %d", temp, t.siteType, &t.seconds) != EOF) { /*Breaks the string temp into access code, domain name*/ /* and domain ending and stores the in the temporary structure*/ t.webAddress = CreateAddress(temp); /*Depending on the first letter of the domain ending, stores*/ /*them into the appropriate array*/ if(t.webAddress.domainEnding[0] == 'c') { /*Finds the index of wherever the website is supposed to go*/ j = IsPresent(comSites, t); /*Stores the website in the proper location*/ comSites[j].webAddress = t.webAddress; /*Stores the siteType in the corresponding location*/ strcpy(comSites[j].siteType, t.siteType); /*Adds the number of hits and the seconds*/ comSites[j].hits += 1; comSites[j].seconds += t.seconds; } else if(t.webAddress.domainEnding[0] == 'g') { j = IsPresent(govSites, t); govSites[j].webAddress = t.webAddress; strcpy(govSites[j].siteType, t.siteType); govSites[j].hits += 1; govSites[j].seconds += t.seconds; } else if(t.webAddress.domainEnding[0] == 'n') { j = IsPresent(netSites, t); netSites[j].webAddress = t.webAddress; strcpy(netSites[j].siteType, t.siteType); netSites[j].hits += 1; netSites[j].seconds += t.seconds; } else { j = IsPresent(eduSites, t); eduSites[j].webAddress = t.webAddress; strcpy(eduSites[j].siteType, t.siteType); eduSites[j].hits += 1; eduSites[j].seconds += t.seconds; } } /*Sorts the arrays*/ SortArray(eduSites, ArrayLength(eduSites)); SortArray(govSites, ArrayLength(govSites)); SortArray(comSites, ArrayLength(comSites)); SortArray(netSites, ArrayLength(netSites)); /*Computes the totals using data from all the arrays*/ ComputeTotals(comSites, pTotalUniqueSites, pTotalNonUniqueSites, pTotalTimeLogged, pTotalFunSites, pTotalSearchSites, pTotalEducationSites, pTotalNewsSites); ComputeTotals(eduSites, pTotalUniqueSites, pTotalNonUniqueSites, pTotalTimeLogged, pTotalFunSites, pTotalSearchSites, pTotalEducationSites, pTotalNewsSites); ComputeTotals(netSites, pTotalUniqueSites, pTotalNonUniqueSites, pTotalTimeLogged, pTotalFunSites, pTotalSearchSites, pTotalEducationSites, pTotalNewsSites); ComputeTotals(govSites, pTotalUniqueSites, pTotalNonUniqueSites, pTotalTimeLogged, pTotalFunSites, pTotalSearchSites, pTotalEducationSites, pTotalNewsSites); /*Prints the results of the read*/ PrintTable(comSites, netSites, eduSites, govSites); /*Caclulates the percentages and prints them*/ CalcStats(TotalUniqueSites, TotalFunSites, TotalSearchSites, TotalNewsSites, TotalEducationSites, TotalTimeLogged, TotalNonUniqueSites); return; }
/* -------------------------------------------------------------------- * FUNCTION NAME: Delete * DESCRIPTION : Delets a label from the ComboBox object using index. * RETURN : None. * NOTES : None. * -------------------------------------------------------------------- */ void ComboBox::Delete(const int& index) { _comboNames.erase(_comboNames.begin() + index); if (_current != 0) --_current; SortArray(); }