本文整理汇总了C++中sortList函数的典型用法代码示例。如果您正苦于以下问题:C++ sortList函数的具体用法?C++ sortList怎么用?C++ sortList使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sortList函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: while
ListNode* 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);
}
示例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);
}
示例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();
}
}
示例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);
}
示例6: sortList
ListNode * sortList(ListNode * head)
{
int iNodeCount = 0;
for (ListNode * pstCount = head; pstCount != NULL; pstCount = pstCount -> next)
{
iNodeCount ++;
}
return sortList(head, iNodeCount);
}
示例7: executeChoice
void 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");
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例13: sortList
void 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();
}
示例14: findSingleOccurenceNumber
int 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];
}
}
示例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;
}