Пример #1
0
    void SortRec(ListNode *head, ListNode *tail){
      if(STACKDEPTH>MAXSD){MAXSD=STACKDEPTH;}
      if(head==NULL) return;
      if(head==tail) return;
      /*if(head->next==tail){
        if(head->val > tail->val){std::swap(head->val,tail->val);}
        return;
      }*/
#if 1
      while((head!=NULL) && (head!=tail)){
        ListNode *p = partition(head,tail);
        ++STACKDEPTH;
        SortRec(head,p);
        --STACKDEPTH;
        head=p->next;
      }
#else
      ListNode *p = partition(head,tail);//
      //if(p!=head)
      {
        ++STACKDEPTH;
        SortRec(head,p);//1,2|1,1
        --STACKDEPTH;
      }
      //if(p!=tail)
      {
        ++STACKDEPTH;
        SortRec(p->next,tail);
        --STACKDEPTH;
      }
#endif

    }
Пример #2
0
/*Updates outcome of game for the player ie: w: win, l: loss, d: draw to output file */
void UpdatePStats(Player p,char c)
{fstream x;
 Player r[50];
 Player s;
 x.open("playerstatc4.dat",ios::binary|ios::in);
 int i,n=0,j,max,mtch=0;
 while(x.read((char*)&s,sizeof(s)))
	{r[n]=s;
	++n;
	 }
 for(i=0;i<n;i++)
	{if(strcmpi(r[i].name,p.name)==0)
		{++mtch;
		switch (c)
			{case 'w':
				++r[i].win;
				r[i].score+=10;
				break;
			case 'l':
				++r[i].loss;
				r[i].score-=2;
				break;
			case 'd':
				++r[i].draw;
				r[i].score+=5;}
		}
	}
 if(mtch==0)
	{switch (c)
		{case 'w':
			p.win=1;
			p.loss=0;
			p.draw=0;
			p.score=10;
			p.rank=1;
			break;
		case 'l':
			p.win=0;
			p.loss=1;
			p.draw=0;
			p.score=-2;
			p.rank=1;
			break;
		case 'd':
			p.win=0;
			p.loss=0;
			p.draw=1;
			p.score=5;
			p.rank=1;}
       r[n]=p;
       ++n;}
 x.close();
 SortRec(r,n);
}
Пример #3
0
 ListNode *sortList(ListNode *head) {
   if(head==NULL)
     return NULL;
   SortRec(head,lastnode(head));//2,1
   return head;
 }