这篇教程C++ sortList函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中sortList函数的典型用法代码示例。如果您正苦于以下问题:C++ sortList函数的具体用法?C++ sortList怎么用?C++ sortList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了sortList函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: h1 ListNode *sortList(ListNode *head) { if (head == NULL) return NULL; int val = head->val; ListNode h1(0), h2(0), h3(0), *t1 = &h1, *t2 = &h2, *t3 = &h3; for (auto p = head; p; p = p->next){ if (p->val == val){ t2 = t2->next = p; }else if (p->val < val){ t1 = t1->next = p; }else{ t3 = t3->next = p; } } t1->next = t2->next = t3->next = NULL; h1.next = sortList(h1.next); for (t1 = &h1; t1->next; t1 = t1->next); t1->next = h2.next; t2->next = sortList(h3.next); return h1.next; }
开发者ID:Anchor89,项目名称:leetcode-2,代码行数:20,
示例2: whileListNode* Solution148::sortList(ListNode *head){ if(head == NULL) return NULL; if(head->next == NULL) return head; ListNode* fast = head->next; ListNode* slow = head; while(fast != NULL && fast->next != NULL) { fast = fast->next->next; slow = slow->next; } fast = slow->next; slow->next = NULL; slow = fast; ListNode* l = sortList(head); ListNode* r = sortList(slow); return merge(l,r);}
开发者ID:zhangxiaoya,项目名称:LeetCodeCPP,代码行数:20,
示例3: while ListNode *sortList(ListNode *head) { if(!head || head->next==NULL) return head; ListNode* pA = head, *pB = head; while( pA && pB && pB->next && pB->next->next ) { pA = pA->next; pB = pB->next->next; } pB= pA->next; pA->next = NULL; pA = head; pA = sortList(pA); pB = sortList(pB); return MergeSortedList(pA, pB); }
开发者ID:668,项目名称:LeetCode,代码行数:20,
示例4: redrawButtons void MultiListBox::sortByColumn(size_t _column, bool _backward) { mSortColumnIndex = _column; if (_backward) { mSortUp = !mSortUp; redrawButtons(); // если было недосортированно то сортируем if (mFrameAdvise) sortList(); flipList(); } else { mSortUp = true; redrawButtons(); sortList(); } }
开发者ID:redkaras,项目名称:Demi3D,代码行数:20,
示例5: sortList ListNode* sortList(ListNode* head) { if (head == NULL || head->next == NULL) { return head; } ListNode *slow = head; ListNode *fast = head; //Get the middle index of list while (fast->next && fast->next->next) { slow = slow->next; fast = fast->next->next; } fast = slow->next; slow->next = NULL; ListNode *p1 = sortList(head); ListNode *p2 = sortList(fast); return merge(p1, p2); }
开发者ID:byhj,项目名称:OJ-LeetCode,代码行数:20,
示例6: sortList ListNode * sortList(ListNode * head) { int iNodeCount = 0; for (ListNode * pstCount = head; pstCount != NULL; pstCount = pstCount -> next) { iNodeCount ++; } return sortList(head, iNodeCount); }
开发者ID:earnestzhao,项目名称:LeetCode,代码行数:11,
示例7: executeChoicevoid executeChoice(int choice, Node ** head){ char * fn = NULL; char * fName = NULL; char * lName = NULL; char * position = NULL; switch(choice) { case 1: printList(*head); break; case 2: fn = getFileName(); FILE* fout = openKnownFile(fn,"w"); printListToFile(*head,fout); fclose(fout); break; case 3: getPositionUser(&position); printSpecificPlayers(*head, position); free(position); break; case 4: *head = sortList(*head, 1); break; case 5: *head = sortList(*head, 2); break; case 6: getPlayerName(&fName,&lName); removeNode(head,fName,lName); free(fName); free(lName); break; default: printf("Sorry incorrect input"); }}
开发者ID:kepler27,项目名称:HW1,代码行数:41,
示例8: sortList ListNode* sortList(ListNode* head) { if(!head || !(head->next)) return head; ListNode *fast = head; ListNode *slow = head; ListNode *pre = NULL; while(fast && fast->next) { fast = fast->next->next; pre = slow; slow = slow->next; } pre->next = NULL; head = sortList(head); slow = sortList(slow); return mergeTwoLists(head,slow); }
开发者ID:FeibHwang,项目名称:OJ-Leetcode,代码行数:21,
示例9: sortList ListNode* sortList(ListNode* head) { if (!head || !head->next) return head; // Find the middle ListNode *slow = head, *fast = head; while (fast->next && fast->next->next) { fast = fast->next->next; slow = slow->next; } // Cut at middle ListNode *p = slow; slow = slow->next; p->next = NULL; ListNode *l1 = sortList(head); ListNode *l2 = sortList(slow); return mergeTwoLists(l1, l2); }
开发者ID:insaneyilin,项目名称:leetcode,代码行数:21,
示例10: sortList/************************************************************************ Set sort mode************************************************************************/void ItemListBase::setSortMode(SortMode mode){ if (d_sortMode != mode) { d_sortMode = mode; if (d_sortEnabled && !d_initialising) sortList(); WindowEventArgs e(this); onSortModeChanged(e); }}
开发者ID:Ocerus,项目名称:Ocerus,代码行数:15,
示例11: request/* Start the request (and complete it) */static void startDir(HttpQueue *q){ HttpConn *conn; HttpTx *tx; HttpRx *rx; MprList *list; MprDirEntry *dp; Dir *dir; cchar *path; uint nameSize; int next; conn = q->conn; rx = conn->rx; tx = conn->tx; dir = conn->data; assert(tx->filename); if (!(rx->flags & (HTTP_GET | HTTP_HEAD))) { httpError(conn, HTTP_CODE_BAD_METHOD, "Bad method"); return; } httpSetHeaderString(conn, "Cache-Control", "no-cache"); httpSetHeaderString(conn, "Last-Modified", conn->http->currentDate); httpSetHeaderString(conn, "Content-Type", "text/html"); parseQuery(conn); if ((list = mprGetPathFiles(tx->filename, MPR_PATH_RELATIVE)) == 0) { httpWrite(q, "<h2>Cannot get file list</h2>/r/n"); outputFooter(q); return; } if (dir->pattern) { filterDirList(conn, list); } sortList(conn, list); /* Get max filename size */ nameSize = 0; for (next = 0; (dp = mprGetNextItem(list, &next)) != 0; ) { nameSize = max((int) strlen(dp->name), nameSize); } nameSize = max(nameSize, 22); path = rx->route->prefix ? sjoin(rx->route->prefix, rx->pathInfo, NULL) : rx->pathInfo; outputHeader(q, path, nameSize); for (next = 0; (dp = mprGetNextItem(list, &next)) != 0; ) { outputLine(q, dp, tx->filename, nameSize); } outputFooter(q); httpFinalize(conn);}
开发者ID:yodamaster,项目名称:appweb,代码行数:56,
示例12: while ListNode *sortList(ListNode *head){ if (head==NULL||head->next==NULL){ return head; } ListNode *slow=head,*fast=head; //假定head存放数据 while (fast->next!=NULL&&fast->next->next!=NULL){ fast=fast->next->next; slow=slow->next; } ListNode *head1=slow->next; ListNode *head2=head; slow->next=NULL;//slow指向null head1=sortList(head1); head2=sortList(head2); return merge(head1,head2); }
开发者ID:JSRGFJZ,项目名称:LeetCode,代码行数:21,
示例13: sortListvoid RobotDecoder::DelayTime::endTiming() { const int timeDelta = _decoder->getTickCount() - _startTime; for (uint i = 0; i < kDelayListSize; ++i) { if (_timestamps[i] == _oldestTimestamp) { _timestamps[i] = ++_newestTimestamp; _delays[i] = timeDelta; break; } } ++_newestTimestamp; _startTime = 0; sortList();}
开发者ID:DrItanium,项目名称:scummvm,代码行数:13,
示例14: findSingleOccurenceNumberint findSingleOccurenceNumber(int *A, int len) { int index; if (A == NULL) return -1; sortList(A, 0, len - 1); for (index = 0; index < len; index += 3) { if (A[index] != A[index + 2]) return A[index]; }}
开发者ID:chirag0103,项目名称:MissionRnD-C-Arrays2-Worksheet,代码行数:13,
示例15: sortList ListNode* sortList(ListNode* head) { int n = getLength(head); if (n == 0 || n == 1) { return head; } n /= 2; ListNode* pl = head; ListNode* pr = head; while (n) { --n; pl = pr; pr = pr->next; } pl->next = NULL; pl = sortList(head); pr = sortList(pr); head = mergeList(pl, pr); return head; }
开发者ID:CWang24,项目名称:LeetCode,代码行数:22,
示例16: getCandidateMoves/*Not implemented - Return possible Moves for Color sorted according to heuristic value*/ListNode *getCandidateMovesOrd(Game *game, Color col){ ListNode *tmp = getCandidateMoves(game, col); return tmp; ListNode *head = tmp; while (head != NULL){ if (head->move == NULL)break; if (isEmpty(game->board[head->move->dest->column][head->move->dest->row])) head->value = -1000; else head->value = scoreChar(game->board[head->move->dest->column][head->move->dest->row], oppositeCol(col)) - scoreChar(game->board[head->move->source->column][head->move->source->row], col); head = head->next; } tmp = sortList(tmp); return tmp;}
开发者ID:orrshilon,项目名称:chessprog,代码行数:14,
示例17: TestsortList1int TestsortList1(){ START_TEST_CASE; DocumentNode *d; d = NULL; d = sortList(d); SHOULD_BE( d == NULL ); freeDocNodeList(d); END_TEST_CASE;}
开发者ID:ChrisHoder,项目名称:Projects,代码行数:13,
示例18: sortList void Armature::updateSlotsZOrder(){ std::vector<Slot*> sortList(_slotList.size()); for(Slot* slot : _slotList) { sortList[(int)slot->getZOrder()] = slot; if(slot->_isDisplayOnStage) { slot->_displayBridge->addDisplay(_display); } } _slotsZOrderChanged = false; }
开发者ID:KingNormac,项目名称:CPlusPlus-Opengl-Dragonbones,代码行数:13,
示例19: if ListNode *sortList(ListNode *head){ if (head == NULL) return head; else if (head->next == NULL) return head; ListNode *slow = head, *fast = head; while (fast->next != NULL && fast->next->next != NULL) { slow = slow->next; fast = fast->next->next; } fast = slow; slow = slow->next; fast->next = NULL; fast = sortList(head); slow = sortList(slow); return mergeList(fast,slow); }
开发者ID:vinctzh,项目名称:leetcode_problems,代码行数:22,
示例20: while ListNode *sortList(ListNode *head) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. if(!head || !head->next) return head; ListNode* slow, *fast; slow = head; fast = slow->next; while(fast){ if(!fast->next || !fast->next->next) break; slow = slow->next; fast = fast->next->next; } fast = slow->next; slow->next = NULL; head = sortList(head); fast = sortList(fast); return merge(head, fast); }
开发者ID:elsucai,项目名称:LC,代码行数:22,
示例21: sll_012_sortvoid sll_012_sort(struct node *head){ int n1=0, n2=0, n3=0; struct node *cur; cur = head; while (cur!= NULL) { if (cur->data == 0) n1++; if (cur->data == 1) n2++; if (cur->data == 2) n3++; cur = cur->next; } sortList(head, n1, n2, n3);}
开发者ID:SudeepaGo,项目名称:MissionRnD-C-LinkedLists-Worksheet,代码行数:13,
示例22: while ListNode *sortList(ListNode *head) { if(head == NULL || head->next == NULL) return head; ListNode *slow = head, *fast = head, *prev; while(fast && fast->next) { prev = slow; slow = slow->next; fast = fast->next->next; } prev->next = NULL; ListNode *part1 = sortList(head); ListNode *part2 = sortList(slow); ListNode dummy(-1); ListNode *cur = &dummy; while(part1 || part2) { int val1 = part1? part1->val: INT_MAX; int val2 = part2? part2->val: INT_MAX; if(val1 <= val2) { cur->next = part1; part1 = part1->next; } else { cur->next = part2; part2 = part2->next; } cur = cur->next; } return dummy.next; }
开发者ID:starmsg,项目名称:problem_set,代码行数:38,
示例23: sortList ListNode* sortList(ListNode* head) { if (!head || !head->next) return head; ListNode* fast = head; ListNode* slow = head; /* * a good way: find the half list. * */ while(fast->next && fast->next->next) { fast = fast->next->next; slow = slow->next; } fast = slow->next; slow->next = NULL; ListNode* p1 = sortList(head); ListNode* p2 = sortList(fast); return merge(p1, p2); }
开发者ID:lxlenovostar,项目名称:algorithm,代码行数:23,
示例24: pushToReadyQueuenode* pushToReadyQueue(struct taskControlBlock tskCtrlBloc[numberOfThreads]){//pushes all tasks into linkedlist with task status as READYnode *first, *newnode, *head, *temp;int len=0,i=0; first = (node *)malloc(sizeof(node)); head = (node *)malloc(sizeof(node)); temp = (node *)malloc(sizeof(node)); head -> TCB = tskCtrlBloc[i]; head-> next = NULL; first = head; printf("first node : %d/n", first->TCB.taskId); i++;while(1)//tskCtrlBloc[i].taskId < numberOfTasks{ if(tskCtrlBloc[i].taskId == numberOfTasks) break; newnode = (node *)malloc(sizeof(node)); newnode->TCB = tskCtrlBloc[i]; newnode->next = NULL; first->next = newnode; first = newnode; printf("new node : %d %d %d/n", first->TCB.taskId, newnode->TCB.taskId,i); i++; } newnode = (node *)malloc(sizeof(node));newnode->TCB = tskCtrlBloc[i];newnode->next = NULL;first->next = newnode;/*while(head != NULL){len++;head = head->next;} printf("Length : %d/n", len); */printList(head);temp = sortList(head);printList(temp);/* printf("HEad : %d/n", temp->TCB.taskId);temp = temp->next;printf("HEad : %d/n", temp->TCB.taskId);*/return temp;}
开发者ID:Manaswi31,项目名称:OS_Scheduler,代码行数:50,
示例25: updateArrows/** * Sorts the saves by date. * @param action Pointer to an action. */void SavedGameState::sortDateClick(Action *){ if (Options::saveOrder == SORT_DATE_ASC) { Options::saveOrder = SORT_DATE_DESC; } else { Options::saveOrder = SORT_DATE_ASC; } updateArrows(); _lstSaves->clearList(); sortList(Options::saveOrder);}
开发者ID:cfailde,项目名称:OpenXcom,代码行数:18,
示例26: sortList ListNode* sortList(ListNode* head) { if(head == NULL || head->next == NULL) return head; ListNode* ptr = head; int i = 0; while(ptr != NULL) { i ++; ptr = ptr->next; } int length = i; i = 0; ListNode* ptr1 = head; ListNode* ptr2 = head; ListNode* prePtr = NULL; while(i < length/2) { i ++; prePtr = ptr2; ptr2 = ptr2->next; } prePtr->next = NULL; prt1 = sortList(ptr1); ptr2 = sortList(ptr2); return merge(ptr1, ptr2); }
开发者ID:huhu213,项目名称:leetcode,代码行数:23,
示例27: processDirstatic void processDir(HttpQueue *q){ HttpConn *conn; HttpTx *tx; HttpRx *rx; MprList *list; MprDirEntry *dp; Dir *dir; uint nameSize; int next; conn = q->conn; rx = conn->rx; tx = conn->tx; dir = conn->data; mprLog(5, "processDir"); mprAssert(tx->filename); httpSetHeaderString(conn, "Cache-Control", "no-cache"); httpSetHeaderString(conn, "Last-Modified", conn->http->currentDate); parseQuery(conn); list = mprGetPathFiles(tx->filename, 1); if (list == 0) { httpWrite(q, "<h2>Can't get file list</h2>/r/n"); outputFooter(q); return; } if (dir->pattern) { filterDirList(conn, list); } sortList(conn, list); /* Get max filename */ nameSize = 0; for (next = 0; (dp = mprGetNextItem(list, &next)) != 0; ) { nameSize = max((int) strlen(dp->name), nameSize); } nameSize = max(nameSize, 22); outputHeader(q, rx->pathInfo, nameSize); for (next = 0; (dp = mprGetNextItem(list, &next)) != 0; ) { outputLine(q, dp, tx->filename, nameSize); } outputFooter(q); httpFinalize(conn);}
开发者ID:varphone,项目名称:appweb-4,代码行数:50,
注:本文中的sortList函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ sorted函数代码示例 C++ sortAllChildren函数代码示例 |