Exemplo n.º 1
0
void TargetList::sortName(int low, int high)
{
    const int MOVING_LEFT = 0;
    const int MOVING_RIGHT = 1;
    if (low < high) {
        int left = low, right = high, currentDirection = MOVING_LEFT;
        QString pivot = rows->at(low)->name->text();
        while (left < right) {
            if (currentDirection == MOVING_LEFT) {
                while (QString::compare(rows->at(right)->name->text(), pivot, Qt::CaseInsensitive) >= 0  && left < right)
                    right--;
                rows->swap(left, right);
                currentDirection = MOVING_RIGHT;
            }
            if (currentDirection == MOVING_RIGHT) {
                while (QString::compare(rows->at(left)->name->text(), pivot, Qt::CaseInsensitive) <= 0  && left < right)
                    left++;
                rows->swap(right, left);
                currentDirection = MOVING_LEFT;
            }
        }
        sortName(low, left-1);
        sortName(right+1, high);
    }
}
Exemplo n.º 2
0
//hall of fame mode
void hof(){
    char ch;
	int i, x;
	char *result;
	int n=0, m = 0;
	FILE *fptr; //create file pointer
	fptr = fopen("HallofFame.txt", "r");  //open HallofFame.txt
	while  ( ( ch = fgetc( fptr ) ) != EOF ){ //determine the number of lines in the file
		if(ch==10)n++;                        //we need that to know how big to make the array later
	}                                         //returns n which is the number of lines
	rewind(fptr);
	struct data entry[n];          //create a data array to hold the records from the HallofFame.txt file
	for(i=0; i<n; i++){            //loop n to read all records from the file
		char info[50];
        fscanf(fptr, "%s", &info); //read a line from the file
		result = strtok(info, ",");
		strcpy(entry[i].name,result); //store name
        result = strtok(NULL, ",");
		entry[i].diff=atoi(result);   //store level
		result = strtok(NULL, ",");
		entry[i].moves=atoi(result); //store steps
		result = strtok(NULL, ",");
		entry[i].time=atoi(result);  //store time from the file
	}
	fclose(fptr);         //close the file after reading all records
	ch = 'p';
	while(ch!=27){
        if(ch==49)sortName(entry, n, 1); //call the required sort method based on user's choice
        if(ch==50)sortDiff(entry, n, 1);
        if(ch==51)sortMoves(entry, n, 1);
        if(ch==52)sortTime(entry, n, 1);
        if(ch==53)sortName(entry, n, 0);
        if(ch==54)sortDiff(entry, n, 0);
        if(ch==55)sortMoves(entry, n, 0);
        if(ch==56)sortTime(entry, n, 0);
        system("cls");
        printf("\nPress 1 to sort by Name (Ascending)\nPress 2 to sort by Level (Ascending)\nPress 3 to sort by Steps (Ascending)\nPress 4 to sort by Time (Ascending)");
	    printf("\nPress 5 to sort by Name (Descending)\nPress 6 to sort by Level (Descending)\nPress 7 to sort by Steps (Descending)\nPress 8 to sort by Time (Descending)");
		printf("\nPress ESC to exit\n");
        ch = getch();
	}
	return;
}
Exemplo n.º 3
0
void CodeMarker::insert(FastSection &fastSection, Node *node, SynopsisStyle style, Status status)
{
    bool inheritedMember = (!node->relates() &&
			    (node->parent() != (const InnerNode *)fastSection.innerNode));
    bool irrelevant = false;

    if (node->access() == Node::Private) {
	irrelevant = true;
    } else if (node->type() == Node::Function) {
	FunctionNode *func = (FunctionNode *) node;
	irrelevant = (inheritedMember
		      && (func->metaness() == FunctionNode::Ctor ||
			  func->metaness() == FunctionNode::Dtor));
    } else if (node->type() == Node::Class || node->type() == Node::Enum
		    || node->type() == Node::Typedef) {
	irrelevant = (inheritedMember && style != SeparateList);
        if (!irrelevant && style == Detailed && node->type() == Node::Typedef) {
            const TypedefNode* typedeffe = static_cast<const TypedefNode*>(node);
            if (typedeffe->associatedEnum())
                irrelevant = true;
        }
    }

    if (!irrelevant) {
        if (status == Compat) {
            irrelevant = (node->status() != Node::Compat);
	} else if (status == Obsolete) {
            irrelevant = (node->status() != Node::Obsolete);
	} else {
            irrelevant = (node->status() == Node::Compat ||
                          node->status() == Node::Obsolete);
	}
    }

    if (!irrelevant) {
	if (!inheritedMember || style == SeparateList) {
	    QString key = sortName(node);
            if (!fastSection.memberMap.contains(key))
		fastSection.memberMap.insert(key, node);
	} else {
	    if (node->parent()->type() == Node::Class) {
		if (fastSection.inherited.isEmpty()
                    || fastSection.inherited.last().first != node->parent()) {
		    QPair<ClassNode *, int> p((ClassNode *)node->parent(), 0);
		    fastSection.inherited.append(p);
		}
		fastSection.inherited.last().second++;
	    }
	}
    }
}
Exemplo n.º 4
0
/*!
  Returns true if \a node represents a reimplemented member function.
  If it is, then it is inserted in the reimplemented member map in the
  section \a fs. And, the test is only performed if \a status is \e OK.
  Otherwise, false is returned.
 */
bool CodeMarker::insertReimpFunc(FastSection& fs, Node* node, Status status)
{
    if (node->access() == Node::Private)
        return false;

    const FunctionNode* fn = static_cast<const FunctionNode*>(node);
    if ((fn->reimplementedFrom() != 0) && (status == Okay)) {
        bool inherited = (!fn->relates() && (fn->parent() != (const InnerNode*)fs.innerNode));
        if (!inherited) {
            QString key = sortName(fn);
            if (!fs.reimpMemberMap.contains(key)) {
                fs.reimpMemberMap.insert(key,node);
                return true;
            }
        }
    }
    return false;
 }
Exemplo n.º 5
0
main(){

BirthInfo person[N];
int choice1, choice2, i=0;


	do{

	printf("Select one from the choices:\n");
	printf("[1] Add Birthday Info\n");
	printf("[2] View All\n");
	printf("[3] View Birthday Celebrant\n");
	printf("[4] Exit\n");
	printf("Choice: ");
	scanf("%d", &choice1);
	printf("\n");

		switch(choice1){

		case 1: addBirthday(person, i);
				i++;
				break;

		case 2: printf("Select kind of view:\n");
				printf("[1] View alphabetically\n[2] View by year\n Choice: ");
				scanf("%d", &choice2);
				if(choice2==1) sortName(person, i);
				else if(choice2==2) sortYear(person, i);
				else printf("Invalid choice\n");
				break;

		case 3: viewCelebrant(person,i);
				break;

		case 4: return(0);

		default: printf("Choice invalid\n");
		}



	}while(choice1!=4);

}
Exemplo n.º 6
0
int main()
{
	int numberOfPlayer=sizeof(player)/sizeof(tableTennis_t);
	
	printf("     Original data\n");
	printPlayer(player,numberOfPlayer);

	sortName(player,numberOfPlayer);
	printf("\n     Title order\n");
	printPlayer(player,numberOfPlayer);

	sortHeight(player,numberOfPlayer);
	printf("\n     Height order\n");
	printPlayer(player,numberOfPlayer);

	sortWeight(player,numberOfPlayer);
	printf("\n     Weight order\n");
	printPlayer(player,numberOfPlayer);

	sortYear(player,numberOfPlayer);
	printf("\n     Year order\n");
	printPlayer(player,numberOfPlayer);
	return 0;
}
Exemplo n.º 7
0
/* Main function */
int main(){
	
	takeCard();
	searchElixir();
	return 0;
	
	system("clear");
	takeCard();
	printf("\nWelcome to my Clash Royal Program, please enter an option:\n");
	printf("\n");
	printf("[0]	:	Deck Maker\n");
	printf("\n");
	printf("Sort by \n");
	printf("[1]	: 	Name\n");
	printf("[2]	: 	Cost [1 - 10]\n");
	printf("[3]	: 	Rarity - Level [Common [1-12], Rare [1-7], Epic [1-4], Legendary[1]]\n");
	printf("[4]	: 	Arena [0 - 8]\n");
	printf("[5] 	: 	Type [Spell, Troop, Building]\n");
	printf("[6]	: 	Hitpoints\n");
	printf("[7]	:	Damage\n");
	printf("[8]	: 	Hit Speed\n");
	printf("[9]	:	Target Type [Air, Ground, Air & Ground]\n");
	printf("[10]	:	Speed [null, slow, medium, fast, very fast]\n");
	printf("\n");
	printf("Search for\n");
	printf("[11]	: 	Name\n");
	printf("[12]	: 	Cost [1 - 10]\n");
	printf("[13]	: 	Rarity by Level [Common [1-12], Rare [1-7], Epic [1-4], Legendary[1]]\n");
	printf("[14]	: 	Arena [0 - 8]\n");
	printf("[15]	: 	Type [Spell, Troop or Building]\n");
	printf("[16]	:	Target Type [Air, Ground, Air & Ground]\n");
	printf("[17]	:	Speed [null, slow, medium, fast, very fast]\n");
	printf("\n");
	printf("[q]	: 	Quit\n\n");

	scanf("%d", &chooseOption); //Stores menu choice into chooseOption
	end();

	if (chooseOption == 0){
		deckMaker();
	}

	if (chooseOption == 1){
		sortName();
	}

	if (chooseOption == 2){
		sortElixir();
	}

	if (chooseOption == 3){
		sortRarity();
	}

	if (chooseOption == 4){
		sortArena();
	}

	if (chooseOption == 5){
		sortType();
	}

	if (chooseOption == 11){
		searchName();
	}

	if (chooseOption == 12){
		searchElixir();
	}

	if (chooseOption == 13){
		searchRarity();
	}

	if (chooseOption == 14){
		searchArena();
	}

	if (chooseOption == 15){
		searchType();
	}
	
	/*
	printf("Again?: \n");
	printf("'1'\t: Yes\n");
	printf("'other'\t: No\n\n");
	scanf("\n%d", &answer);

	if (answer == 1){
		system("clear");
		main();
		return 0;
	}
	*/

	end();
	return 0;
}