Exemplo n.º 1
0
int main() {
  try {
    pis("zacatek");
    Queue<int> q;
    q.add(1); q.add(2); q.add(3); 
    pis("q1");
    Queue<int> q1 = q; 
    Queue<int> q2;
    q2=q;
    pis("q1konec");
    q.remove(); q.remove();
    for (int i=10; i<=35; i++)
      q.add(i);
    while (!q.empty()) {
        cout << q.front() << ' ';
        q.remove();
    }
    cout << endl;
    while (!q1.empty()) {
        cout << q1.front() << ' ';
        q1.remove();
    }
    cout << endl;
    while (!q2.empty()) {
        cout << q2.front() << ' ';
        q2.remove();
    }
    cout << endl;
  }
  catch (const char* s) {
    cout << "chyba: " << s << endl;
  }
  //system("PAUSE");
  return 0;
}
Exemplo n.º 2
0
int BinarySearchTree :: breadthFirstTraversal (int number) const {
    
    Queue queue;
    BSTNode* current = root;
    queue.add(root);
    int count = 0;
    while (current != NULL) {
        
        //If there is right child, add it to queue
        if (current -> getLeft() != 0)
            queue.add(current -> getLeft());
        
        //If there is right child, add it to queue
        if (current -> getRight() != 0)
            queue.add(current -> getRight());
        
        queue.removeFromHead(current);
        if (current->getValue() == number) {
            return count;
        }
        current = getBSTNodeFromQueue(queue);
        count++;
    }
    return count;
}// end breadthFirstTraversal
Exemplo n.º 3
0
int main() {
  try {
    Queue<int> q;
    q.add(1); q.add(2); q.add(3); 
    q.remove(); q.remove(); q.remove();
    for (int i=10; i<=28; i++)
      q.add(i);
    Queue<int> r = q;
    while (!q.empty()) {
        cout << q.front() << ' ';
        q.remove();
    }
    cout << endl;
    while (!r.empty()) {
        cout << r.front() << ' ';
        r.remove();
    }
    cout << endl;
  }
  catch (const char* s) {
    cout << "chyba: " << s << endl;
  }
  //system("PAUSE");
  return 0;
}
Exemplo n.º 4
0
vector<int> Graph::BFS(int x) {
	Queue Q;
	bool *visited = new bool[n+1];
	int i;
	vector<int> conComp;
	for (i = 1; i <= n; ++i)
	visited[i] = false;
	Q.add(x);
	visited[x] = true;
	//cout << "Breadth First Search starting from vertex ";
	//cout << x << " : " << endl;
	while (!Q.isEmpty()) 
	{
		int k = Q.get();
		//cout << k << " ";
		for (i = 1; i <= n; ++i)
		{
			if (isConnected(k, i) && !visited[i]) 
			{
				Q.add(i);
				visited[i] = true;
				conComp.push_back(i);

			}
		}
	}
	//cout << endl;
	delete [] visited;
	return conComp; // return connected components
}
    public void connect(TreeLinkNode root) {
        if (root == null)
            return;
        Queue<TreeLinkNode> queue = new LinkedList<TreeLinkNode>();
        queue.add(root);
        queue.add(null);

        while (!queue.isEmpty()) {
            TreeLinkNode out = queue.remove();
            if (out != null) {
                out.next = queue.peek();
                if (out.left != null)
                    queue.add(out.left);
                if (out.right != null)
                    queue.add(out.right);
            } else {
                if (!queue.isEmpty()) {
                    queue.add(null);
                }

            }

        }

    }
void Graph::minPath(int start, int target) {
    Queue Q;
    int i, p, q;
    bool found;
    struct aux {
        int current, prev;
    };
    aux *X = new aux[n+1];
    int *Y = new int[n+1];
    bool *visited = new bool[n+1];
    for (i = 1; i <= n; ++i)
        visited[i] = false;
    Q.add(start);
    visited[start] = true;
    found = false;
    p = q = 0;
    X[0].current = start;
    X[0].prev = 0;
    while (!Q.isEmpty() && !found) {
        int k = Q.get();
        for (i = 1; i <= n && !found; ++i)
            if (isConnected(k, i) && !visited[i]) {
                Q.add(i);
                ++q;
                X[q].current = i;
                X[q].prev = p;
                visited[i] = true;
                if (i == target) found = true;
            }
        ++p;
    }
    cout << "The minimum length path from " << start;
    cout << " to " << target << " is : " << endl;
    p = 0;
    while (q) {
        Y[p] = X[q].current;
        q = X[q].prev;
        ++p;
    }
    Y[p] = X[0].current;
    for (q = 0; q <= p/2; ++q) {
        int temp = Y[q];
        Y[q] = Y[p-q];
        Y[p-q] = temp;
    }
    for (q = 0; q <= p; ++q)
        cout << Y[q] << " ";
    cout << endl;
    cout << "Length = " << q-1 << endl;
    delete [] visited;
    delete [] X;
    delete [] Y;
}
Exemplo n.º 7
0
void ares_gethostbyname(ares_channel channel,
                                     const char *name,
                                     int family,
                                     ares_host_callback callback,
                                     void *arg)
{
//	if( QueueManager::manager()->check_cache(name,callback,arg) )
//		return;
	Queue *q = (Queue *)channel;
	q->add(name,s3eTimerGetUTC()+5000,callback,arg);
	QueueManager::manager()->step(q);
/*	{
		// DEBUG
						hostent ent;
						//char *hostname = new char[current->first()->host.size()+1];
						//memcpy(hostname,current->first()->host.c_str(),current->first()->host.size());
						//hostname[current->first()->host.size()] = 0;
						//ent.h_name = hostname;
						ent.h_name = (char *)name;
						ent.h_length = 4;
						char *addr_list[2];
						char *aliases[1] = { NULL };
						s3eInetIPAddress result;
						s3eInetAton(&result,"78.40.184.246");
						addr_list[0] = (char*)&result;
						addr_list[1] = NULL;
						ent.h_addr_list = addr_list;
						ent.h_aliases = aliases;
						ent.h_addrtype = AF_INET;
						//current->first_done(ARES_SUCCESS,&ent);
						callback(arg,ARES_SUCCESS,0,&ent);
	}
*/
}
Exemplo n.º 8
0
void addStudents(){
	ifs.getline(stream, 10);
	int numStudents = atoi(stream);
	totalNumStudents += numStudents;
	for (int i = 0; i < numStudents; ++i){
		ifs.getline(stream, 10);
		q.add(atoi(stream));
	}
}
Exemplo n.º 9
0
int main3() {
  try {
    Queue<int> q;
    q.add(1); q.add(2); q.add(3); q.remove(); q.remove();
    for (int i=10; i<=35; i++)
      q.add(i);
    while (!q.empty()) {
        cout << q.front() << ' ';
        q.remove();
    }
    cout << endl;
  }
  catch (const char* s) {
    cerr << "error: " << s << endl;
  }
  system("PAUSE");
  return 0;
}
void streamInsertionOthersTest() {
    Vector<int> v;
    v.add(14);
    v.add(42);
    cout << "Vector: " << v << endl;

    Stack<int> s;
    s.add(14);
    s.add(42);
    cout << "Stack: " << s << endl;

    Queue<int> q;
    q.add(14);
    q.add(42);
    cout << "Queue: " << q << endl;

    PriorityQueue<int> pq;
    pq.add(14, 1);
    pq.add(42, 2);
    cout << "PriorityQueue: " << pq << endl;

    Grid<int> grid;
    grid.resize(2, 2);
    grid.fill(14);
    cout << "Grid: " << grid << endl;

    Map<string, Vector<int>> map;
    map.add("corfu", v);
    cout << "Map<string, Vector>: " << map << endl;

    HashMap<Stack<int>, Vector<int>> hashmap;
    hashmap.add(s, v);
    cout << "Map<Stack, Vector>: " << hashmap << endl;

    Set<int> set;
    set.add(14);
    set.add(42);
    cout << "Set: " << set << endl;

    HashSet<Set<int>> hashset;
    hashset.add(set);
    cout << "HashSet<Set>: " << hashset << endl;

    Graph<DumbNode, DumbEdge> graph;
    graph.addNode("a");
    graph.addNode("b");
    graph.addNode("c");
    graph.addNode("d");
    graph.addNode("e");
    graph.addArc("a", "b");
    graph.addArc("a", "d");
    graph.addArc("b", "c");
    graph.addArc("b", "d");
    graph.addArc("c", "b");
    graph.addArc("c", "e");
    cout << "Graph: " << graph << endl;
}
Exemplo n.º 11
0
int main() {
    Queue x;
    x.add("George").add("Washington").add("was").add("here.");
    cout <<endl;

    // x.add("BREAK!");

    x.remove();
    x.add("NOT!");
    cout <<endl;
    x.remove();
    x.add("Just kidding.");
    cout <<endl;
    x.remove();
    x.add("But seriously.");
    cout <<endl;
    x.remove();

    x.remove();
    x.remove();
    x.add("Would a man joke?").add("Or would he choke?");
    x.remove();
    x.add("How crazy is Hollywood?");
    x.remove();
    x.remove();

    x.remove();

    return 0;
} //main()
Exemplo n.º 12
0
int main(){
    Queue a = Queue();
    a.add("a");
    cout << a.getUsed() << endl;
    a.add("b");
    a.add("c");
    a.add("d");
    cout << a.remove() << endl;
    cout << a.remove() << endl;
    cout << a.getUsed() << endl;
    a.add("e");
    a.add("f");
    a.add("break");
    cout << a.getUsed() << endl;
    cout << a.remove() << endl;
    cout << a.remove() << endl;
    cout << a.remove() << endl;
    a.add("fake");
    cout << a.getUsed() << endl;
    cout << a.remove() << endl;
    cout << a.remove() << endl;
    cout << a.remove() << endl;
    cout << a.getUsed() << endl;
    
    //system("pause");
    return 0;
} //main()
Exemplo n.º 13
0
void Graph::BFS(int x) {
    Queue Q;
    bool *visited = new bool[n+1];
    int i;
    for (i = 1; i <= n; ++i)
        visited[i] = false;
    Q.add(x);
    visited[x] = true;
    cout << "Breadth First Search starting from vertex ";
    cout << x << " : " << endl;
    while (!Q.isEmpty()) {
        int k = Q.get();
        cout << k << " ";
        for (i = 1; i <= n; ++i)
            if (isConnected(k, i) && !visited[i]) {
                Q.add(i);
                visited[i] = true;
            }
    }
    cout << endl;
    delete [] visited;
}
Exemplo n.º 14
0
int main(){
  char str[5][10]={
    "one", "two", "three", "four", "five"
  };
  char s[100];
  Queue q;
  int i;
  for(i=0;i<5;i++){
    q.add(str[i]);
  }

  while(!q.isEmpty()){
    q.remove(s);
    std::cout<<s<<std::endl;
  }

  return 0;
}
Exemplo n.º 15
0
int main() {
        Queue<int> qi;
        cout << qi << endl;

        int ival;
        for ( ival = 0; ival < 10; ++ival )
                qi.add( ival );
        cout << qi << endl;

        int err_cnt = 0;
        for ( ival = 0; ival < 10; ++ival ) {
                int qval = qi.remove();
                if ( ival != qval ) err_cnt++;
        }

        cout << qi << endl;
        if ( !err_cnt )
                cout << "!! queue executed ok\n";
        else cout << "?? queue errors: " << err_cnt << endl;
        return 0;
}
Exemplo n.º 16
0
void DataUpload::action() const {
// Make the xml files to upload
	string name("/tmp/data.");
	time_t now = time(0);
//	struct tm * mytm = localtime(&now);
//	char buf[20];
	
	// Implement purge_to:
	journal.purge(var.purgeTo);

	char buf[20];
	if (conf.getSiteId() < 0)		// Treat negative siteid as MAC address instead
		strcpy(buf, getmac());
	else {
		snprintf(buf, sizeof(buf), "%d", conf.getSiteId());
	}
	name += buf;
	name += ".xml";
	DEBUG cerr << "DataUpload::action Got name as " << name << "\n";
	journal.xml(name.c_str());
	
	queue.add(new DataUpload(timeMod(var.dataUpload, 1)));
	var.lastUpload = now;
	
	// Call send.sh
	string command(conf.serverComms);
	command += " ";
	command += buf;
	command +=" ";
	command += conf.serverUrl;
	command += " &";	// background it
	DEBUG cerr << "Invoking comms: '" << command;
	int retval = system(command.c_str());
	DEBUG cerr << "' Retval from system() is " << retval << endl;
	// Do a replace in case there is still a GetResponse in the queue
	queue.replace<GetResponse>(new GetResponse(now + 30));
}
Exemplo n.º 17
0
bool QueueView::dropMimeData(QTreeWidgetItem* parent, int index, const QMimeData* data, Qt::DropAction action)
{
	if(action == Qt::IgnoreAction)
		return true;
	
	int queueTo = parent->treeWidget()->indexOfTopLevelItem(parent);

	if(data->hasFormat("application/x-fatrat-transfer"))
	{
		g_queuesLock.lockForRead();
		
		QByteArray encodedData = data->data("application/x-fatrat-transfer");
		QDataStream stream(&encodedData, QIODevice::ReadOnly);
		int queueFrom;
		QList<int> transfers;
		QList<Transfer*> objects;
		Queue* q;
		
		stream >> queueFrom >> transfers;
		
		if(queueFrom != queueTo && queueTo < g_queues.size())
		{
			q = g_queues[queueFrom];
			q->lockW();
			
			for(int i=0;i<transfers.size();i++)
				objects << q->take(transfers[i]-i, true);
			
			q->unlock();
			
			q = g_queues[queueTo];
			q->add(objects);
		}
		
		g_queuesLock.unlock();
	}
Exemplo n.º 18
0
int main()
{
	Creature *player1Creatures = NULL;
	Creature *player2Creatures = NULL;

	Queue player1Lineup;
	Queue player2Lineup;

	Stack player1Loserpile;
	Stack player2Loserpile;

	Queue allPile;
	Queue tmpQueue;

	int player1Points = 0;
	int player2Points = 0;

	int numofFighters;
	bool viewtop3 = false;

	cout << "How many fighters do you want both players to have? (Must have at least 3) " << endl;
	cin >> numofFighters;

	while (numofFighters < 3)
	{
		cout << "Must have at least 3 fighters for both players! " << endl;
		cin >> numofFighters;

		// make sure that users don't accidently type characters
		while (!cin)
		{
			cout << "Error. Integers only. " << endl;
			cin.clear();
			cin.ignore();

			cin >> numofFighters;
		}
		cin.ignore();

	}

	while(true)
	{
		int choice;

		cout << endl;
		cout << "1. Player 1 selections " << endl;
		cout << "2. Player 2 selections " << endl;
		cout << "3. View line up " << endl;
		cout << "4. View loser's pile " << endl;
		cout << "5. Fight " << endl;
		cout << "6. Top 3 Finishers " << endl;
		cout << "7. View final order of all fighters " << endl;
		cout << "8. Exit " << endl;

		cin >> choice;

		// make sure that users don't accidently type characters
		while (!cin)
		{
			cout << "Error. Integers only. " << endl;
			cin.clear();
			cin.ignore();

			cin >> choice;
		}
		cin.ignore();

		switch (choice)
		{

		case 1:
		{
			if (player1Lineup.isEmpty() == false)
			{
				cout << "\nLine up has already been created! " << endl;
				break;
			}

			for (int i = 0; i < numofFighters; i++)
			{

				string selection;
				cout << "\nPlease select fighter " << i+1 << "." << endl;
				cout << "(1)Barbarian, (2)Goblin, (3)ReptilePeople, (4)BlueMen, (5)Shadow " << endl;
				cin >> selection;

				while (!(selection == "1" || selection == "2" || selection == "3" || selection == "4" || selection == "5"))
				{
					cout << "That creature does not exist! Try again " << endl;
					cin >> selection;
				}

				cin.ignore();

				if (selection == "1")
				{
					string name;
					string team1 = "Team 1: ";
					Barbarian *barb = NULL;
					player1Creatures = new Barbarian();

					cout << "Please enter the name for the fighter" << endl;
					getline(cin, name);

					team1.append(name);

					player1Creatures->setrealName(team1);

					player1Lineup.add(player1Creatures);
				}

				if (selection == "2")
				{
					string name;
					string team1 = "Team 1: ";
					Goblin *gob = NULL;
					player1Creatures = new Goblin();

					cout << "Please enter the name for the fighter" << endl;
					getline(cin, name);

					team1.append(name);

					player1Creatures->setrealName(team1);

					player1Lineup.add(player1Creatures);
				}

				if (selection == "3")
				{
					string name;
					string team1 = "Team 1: ";
					ReptilePeople *reptile = NULL;
					player1Creatures = new ReptilePeople();

					cout << "Please enter the name for the fighter" << endl;
					getline(cin, name);

					team1.append(name);

					player1Creatures->setrealName(team1);

					player1Lineup.add(player1Creatures);
				}

				if (selection == "4")
				{
					string name;
					string team1 = "Team 1: ";
					BlueMen *blue = NULL;
					player1Creatures = new BlueMen();

					cout << "Please enter the name for the fighter" << endl;
					getline(cin, name);

					team1.append(name);

					player1Creatures->setrealName(team1);

					player1Lineup.add(player1Creatures);
				}

				if (selection == "5")
				{
					string name;
					string team1 = "Team 1: ";
					Shadow *shade = NULL;
					player1Creatures = new Shadow();

					cout << "Please enter the name for the fighter" << endl;
					getline(cin, name);

					team1.append(name);

					player1Creatures->setrealName(team1);

					player1Lineup.add(player1Creatures);
				}

			} 

			break;
		}

		case 2:
		{

			if (player2Lineup.isEmpty() == false)
			{
				cout << "\nLine up has already been created! " << endl;
				break;
			}

			for (int i = 0; i < numofFighters; i++)
			{

				string selection;
				cout << "\nPlease select fighter " << i + 1 << "." << endl;
				cout << "(1)Barbarian, (2)Goblin, (3)ReptilePeople, (4)BlueMen, (5)Shadow " << endl;
				cin >> selection;


				while (!(selection == "1" || selection == "2" || selection == "3" || selection == "4" || selection == "5"	))
				{
					cout << "That creature does not exist! Try again " << endl;
					cin >> selection;
				}

				cin.ignore();

				if (selection == "1")
				{
					string name;
					string team2 = "Team 2: ";
					Barbarian *barb = NULL;
					player2Creatures = new Barbarian();

					cout << "Please enter the name for the fighter" << endl;
					getline(cin, name);

					team2.append(name);

					player2Creatures->setrealName(team2);

					player2Lineup.add(player2Creatures);
				}

				if (selection == "2")
				{
					string name;
					string team2 = "Team 2: ";
					Goblin *gob = NULL;
					player2Creatures = new Goblin();

					cout << "Please enter the name for the fighter" << endl;
					getline(cin, name);

					team2.append(name);

					player2Creatures->setrealName(team2);

					player2Lineup.add(player2Creatures);
				}

				if (selection == "3")
				{
					string name;
					string team2 = "Team 2: ";
					ReptilePeople *reptile = NULL;
					player2Creatures = new ReptilePeople();

					cout << "Please enter the name for the fighter" << endl;
					getline(cin, name);

					team2.append(name);

					player2Creatures->setrealName(team2);

					player2Lineup.add(player2Creatures);
				}

				if (selection == "4")
				{
					string name;
					string team2 = "Team 2: ";
					BlueMen *blue = NULL;
					player2Creatures = new BlueMen();

					cout << "Please enter the name for the fighter" << endl;
					getline(cin, name);

					team2.append(name);

					player2Creatures->setrealName(team2);

					player2Lineup.add(player2Creatures);
				}

				if (selection == "5")
				{
					string name;
					string team2 = "Team 2: ";
					Shadow *shade = NULL;
					player2Creatures = new Shadow();

					cout << "Please enter the name for the fighter" << endl;
					getline(cin, name);

					team2.append(name);

					player2Creatures->setrealName(team2);

					player2Lineup.add(player2Creatures);
				}

			}
			break;
		}

		case 3:
		{

			// view line up

			string number;


			do
			{

				cout << "Which line up do you wish to view? (1)Player1 or (2)Player2? " << endl;
				cin >> number;

				if (number == "1")
				{

					if (player1Lineup.isEmpty() == true)
					{
						cout << "The lineup for player 1 is empty! " << endl;
						break;
					}

					else
					{
						player1Lineup.view();
						cout << endl;
					}

				}

				else if (number == "2")
				{

					if (player2Lineup.isEmpty() == true)
					{
						cout << "The lineup for player 2 is empty! " << endl;
					}

					else
					{
						player2Lineup.view();
						cout << endl;
					}

				}

				else
				{
					cout << "Must select (1)Player1 or (2)Player2. " << endl << endl;
				}

			} while (!(number == "1" || number == "2"));

			break;
		}



		case 4:
		{

			// view pile

			int number;

			cout << "Which pile do you wish to view? (1)Player1 or (2)Player2? " << endl;
			cin >> number;

			if (number == 1)
			{

				while (player1Loserpile.isEmpty() == true)
				{
					cout << "The pile for player 1 is empty! " << endl;
					break;
				}


				player1Loserpile.view();
				cout << endl;
				
			}

			else if (number == 2)
			{

				while (player2Loserpile.isEmpty()==true)
				{
					cout << "The pile for player 2 is empty! " << endl;
					break;
				}

				player2Loserpile.view();
				cout << endl;
				
			}


			else
			{
				cout << "Must select (1)Player1 or (2)Player2. " << endl;
			}

			break;
		}


		case 5:
		{
			// fight section

			if (player1Lineup.isEmpty() == true)
			{
				cout << "\nYou didn't create a team for player 1!! Create one first. " << endl;
				break;
			}

			else if (player2Lineup.isEmpty() == true)
			{
				cout << "\nYou didn't create a team for player 2!! Create one first. " << endl;
				break;
			}

			else
			{
				while (player1Lineup.isEmpty() == false  && player2Lineup.isEmpty() == false)
				{
					cout << "\nThe fight has begun.. " << endl;

					fightSimulator(player1Lineup.getCreature(), player2Lineup.getCreature());

					if (player1Lineup.getCreature()->liveCreature() == true)
					{
						// move the loser to loser's pile
						cout << player1Lineup.getCreature()->getrealName() << " has won." << endl;
						player2Loserpile.add(player2Lineup.getCreature());
						player2Lineup.remove();

						// give winner some healing and move it to end of line
						Creature *tempCreature = player1Lineup.getCreature();
						tempCreature->addPoint();
						tempCreature->replenish();

						player1Lineup.remove();
						player1Lineup.add(tempCreature);

						// give player 1 points for winning
						player1Points++;
					}

					else if (player2Lineup.getCreature()->liveCreature() == true)
					{
						// move the loser to loser's pile
						cout << player2Lineup.getCreature()->getrealName() << " has won." << endl;
						player1Loserpile.add(player1Lineup.getCreature());
						player1Lineup.remove();

						// give winner some healing and move it to end of line
						Creature *tempCreature = player2Lineup.getCreature();
						tempCreature->addPoint();
						tempCreature->replenish();

						player2Lineup.remove();
						player2Lineup.add(tempCreature);
						
						// give player 2 points for winning
						player2Points++;

				
					}

					if (player1Lineup.isEmpty() == true || player2Lineup.isEmpty() == true)
					{

						cout << "\nThe fight has finished.. " << endl;
						break;
					}

				}

				cout << endl;

				if (player1Points > player2Points)
				{
					cout << "Player 1 has won with " << player1Points << " points." << endl;
					cout << "Player 2 has lost with " << player2Points << " points." << endl;
				}

				else if (player2Points > player1Points)
				{
					cout << "Player 2 has won with " << player2Points << " points." << endl;
					cout << "Player 1 has lost with " << player1Points << " points." << endl;
				}
				
			}

			break;
		}

		case 6:
		{

			if (player1Points == 0 && player2Points == 0)
			{
				cout << "The fight hasn't happened yet! " << endl;
				break;
			}

			if (player1Lineup.isEmpty() == true && player2Lineup.isEmpty() == true)
			{
				cout << "There's no team! All sides are empty. " << endl;
				break;
			}

			int currentplaceFinish = 1;
			int currentfinisherScore;
			

			Queue *newPile = new Queue;
			
			// removing all combatants from every lineup and queue
			// and putting them into one big queue with sorted order
			for (int i = 0; player1Lineup.isEmpty()== false; i++)
			{

				Creature *tempCreature = player1Lineup.getCreature();
			
				player1Lineup.remove();
				newPile->addSort(tempCreature);
			}

			for (int i = 0;  player2Lineup.isEmpty() == false; i++)
			{
				Creature *tempCreature = player2Lineup.getCreature();

				player2Lineup.remove();
				newPile->addSort(tempCreature);
			}

			for (int i = 0; player1Loserpile.isEmpty() == false; i++)
			{
				Creature *tempCreature = player1Loserpile.getCreature();

				player1Loserpile.remove();
				newPile->addSort(tempCreature);
				
			}

			for (int i = 0; player2Loserpile.isEmpty() == false; i++)
			{
				Creature *tempCreature = player2Loserpile.getCreature();

				player2Loserpile.remove();
				newPile->addSort(tempCreature);
			}


			while(!(newPile->isEmpty()==true))
			{
				allPile.addSort(newPile->getCreature());
				newPile->remove();
			}

			// determining the top 3 
			while (currentplaceFinish <= 3 && (!(allPile.isEmpty() == true)))
			{
				
				Creature* tempCreature = allPile.getCreature();
				currentfinisherScore = tempCreature->getPoints();

				cout << "In place " << currentplaceFinish << " with " << currentfinisherScore << " points is " << allPile.getCreature()->getrealName() << endl;
				allPile.remove();

				currentplaceFinish++;
				tmpQueue.add(tempCreature);  // add top 3 back to temporary queue

			}


			// add top 3 from temporary queue back to allPile
			while (tmpQueue.isEmpty() == false)
			{
				allPile.addSort(tmpQueue.getCreature());
				tmpQueue.remove();
			}

			viewtop3 = true;
			delete newPile;

			break;
		}

		case 7:
		{
			if (allPile.isEmpty() == true)
			{
				cout << "Currently emptied or has been viewed already!" << endl;
			}

			else if (viewtop3 == false)
			{
				cout << "Top 3 has not been decided yet to view all orders of fighters " << endl;
				break;
			}

			else
			{
				cout << "\nThe final order of all the fighters after displaying the top 3 finishers are: " << endl;

				allPile.view();

			}

			break;
		}

		case 8:
		{
			exit(0);
		}

		default:
		{
			cout << endl;
			cout << "Not a choice, please enter a value between 1 and 8. " << endl;
			break;
		}
	
		} // end of switch statement

	} 

	
	delete player1Creatures;
	delete player2Creatures;

	return 0;

}
Exemplo n.º 19
0
void StatusUpdate::action() const {
	systemStatus();	// do it
	// reschedule 
	queue.add(new StatusUpdate(timeMod(var.statusUpdate, 0)));
}
Exemplo n.º 20
0
void Consolidate::action() const {
	current.consolidate(journal);
	queue.add(new Consolidate(timeMod(var.sampleFrequency, 0)));
}
Exemplo n.º 21
0
/*Add the first input word as first ladder in our future list*/
void createFirstLadder (Queue<Vector<string>> & list, string & firstWord){
    Vector<string> word;
    word.add(firstWord);
    list.add(word);
}
Exemplo n.º 22
0
void MainWindow::addTransfer(QString uri, Transfer::Mode mode, QString className, int qSel)
{
	Queue* queue = 0;
	
	if(m_dlgNewTransfer)
	{
		m_dlgNewTransfer->addLinks(uri);
		return;
	}
	if(qSel < 0)
	{
		qSel = getSelectedQueue();
		if(qSel < 0)
		{
			if(g_queues.size())
				qSel = 0;
			else
				return;
		}
	}
	
	m_dlgNewTransfer = new NewTransferDlg(this);
	
	m_dlgNewTransfer->setWindowTitle(tr("New transfer"));
	m_dlgNewTransfer->m_nQueue = qSel;
	m_dlgNewTransfer->m_strURIs = uri;
	
	if(!uri.isEmpty() && className.isEmpty())
	{
		QStringList l = uri.split('\n', QString::SkipEmptyParts);
		Transfer::BestEngine eng = Transfer::bestEngine(l[0], mode);
		
		if(eng.type != Transfer::ModeInvalid)
			m_dlgNewTransfer->m_mode = eng.type;
	}
	else
	{
		m_dlgNewTransfer->m_mode = mode;
		m_dlgNewTransfer->m_strClass = className;
	}
	
	QList<Transfer*> listTransfers;
	
show_dialog:
	try
	{
		QStringList uris;
		int sep = getSettingsValue("link_separator").toInt();
		
		if(m_dlgNewTransfer->exec() != QDialog::Accepted)
			throw RuntimeException();
		
		if(!sep)
			uris = m_dlgNewTransfer->m_strURIs.split('\n', QString::SkipEmptyParts);
		else
			uris = m_dlgNewTransfer->m_strURIs.split(QRegExp("\\s+"), QString::SkipEmptyParts);
		
		if(uris.isEmpty())
			throw RuntimeException();

		for(int i=0;i<uris.size();i++)
		{
			QString trm = uris[i].trimmed();
			
			if(trm.isEmpty())
			{
				uris.removeAt(i);
				i--;
			}
			else
				uris[i] = trm;
		}
		
		int detectedClass = m_dlgNewTransfer->m_nClass; // used for the multiple cfg dialog
		for(int i=0;i<uris.size();i++)
		{
			Transfer* d;
			
			int classID;
			if(m_dlgNewTransfer->m_nClass == -1)
			{
				// autodetection
				Transfer::BestEngine eng;
				
				if(m_dlgNewTransfer->m_mode == Transfer::Download)
					eng = Transfer::bestEngine(uris[i], Transfer::Download);
				else
					eng = Transfer::bestEngine(m_dlgNewTransfer->m_strDestination, Transfer::Upload);
				
				if(eng.nClass < 0)
					throw RuntimeException(tr("Couldn't autodetect transfer type for \"%1\"").arg(uris[i]));
				else
					classID = eng.nClass;

				if(detectedClass == -1)
					detectedClass = classID;
				else if(detectedClass >= 0 && detectedClass != classID)
					detectedClass = -2;
			}
			else
				classID = m_dlgNewTransfer->m_nClass;
			
			d = Transfer::createInstance(m_dlgNewTransfer->m_mode, classID);
			
			if(d == 0)
				throw RuntimeException(tr("Failed to create a class instance."));
			
			listTransfers << d;
			
			QString source, destination;
			
			source = uris[i].trimmed();
			destination = m_dlgNewTransfer->m_strDestination;
			
			if(!m_dlgNewTransfer->m_auth.strUser.isEmpty())
			{
				QString& obj = (m_dlgNewTransfer->m_mode == Transfer::Download) ? source : destination;
				
				QUrl url = obj;
				if(url.userInfo().isEmpty())
				{
					url.setUserName(m_dlgNewTransfer->m_auth.strUser);
					url.setPassword(m_dlgNewTransfer->m_auth.strPassword);
				}
				obj = url.toString();
			}
			
			d->init(source, destination);
			d->setUserSpeedLimits(m_dlgNewTransfer->m_nDownLimit,m_dlgNewTransfer->m_nUpLimit);
		}
		
		// show the transfer details dialog
		if(m_dlgNewTransfer->m_bDetails)
		{
			// show a typical transfer propeties dialog
			if(listTransfers.size() == 1)
			{
				WidgetHostDlg dlg(this);
				m_dlgNewTransfer->setWindowTitle(tr("Transfer details"));
				
				if(WidgetHostChild* q = listTransfers[0]->createOptionsWidget(dlg.getChildHost()))
				{
					dlg.addChild(q);
					
					if(dlg.exec() != QDialog::Accepted)
						throw RuntimeException();
				}
			}
			else if(detectedClass >= 0) // show a dialog designed for multiple
			{
				if(!Transfer::runProperties(this, m_dlgNewTransfer->m_mode, detectedClass, listTransfers))
					throw RuntimeException();
			}
			else
			{
				QMessageBox::warning(this, "FatRat", tr("Cannot display detailed configuration when there are multiple transfer types used."));
			}
		}
		
		if(!m_dlgNewTransfer->m_bPaused)
		{
			foreach(Transfer* d, listTransfers)
				d->setState(Transfer::Waiting);
		}
		
		queue = getQueue(m_dlgNewTransfer->m_nQueue, false);
		
		if(!queue)
			throw RuntimeException(tr("Internal error."));
		
		queue->add(listTransfers);
	}
	catch(const RuntimeException& e)
	{
		qDeleteAll(listTransfers);
		listTransfers.clear();
		if(!e.what().isEmpty())
		{
			QMessageBox::critical(this, tr("Error"), e.what());
			goto show_dialog;
		}
	}
	
	delete m_dlgNewTransfer;
	m_dlgNewTransfer = 0;
	
	if(queue != 0)
		doneQueue(queue,false);
	
	Queue::saveQueuesAsync();
}
Exemplo n.º 23
0
/**
 * @brief creating new transfer
 *
 * @param m_strURIs transfers urls
 * @param downloadTrueUploadFalse boolean value for download or upload
 * @param m_nClass download type default -1
 * @param m_strDestination destination fo transfer
 * @param m_nDownLimit down limit of transfer
 * @param m_nUpLimit up limit of transfer
 * @param m_bPaused boolean true if transfer is paused
 */
void TransfersMethods::createTransfer(QString m_strURIs,bool downloadTrueUploadFalse,int m_nClass,QString m_strDestination,
                                     int m_nDownLimit,int m_nUpLimit,bool m_bPaused)
{
     Queue* queue = 0;
     QList<Transfer*> listTransfers;
     try
     {
         QStringList uris;
             uris = m_strURIs.split('\n', QString::SkipEmptyParts);
         if(uris.isEmpty())
             throw RuntimeException();
         for(int i=0;i<uris.size();i++)
         {
             QString trm = uris[i].trimmed();

             if(trm.isEmpty())
             {
                 uris.removeAt(i);
                 i--;
             }
             else
                 uris[i] = trm;
         }
         int detectedClass = m_nClass;
         for(int i=0;i<uris.size();i++)
         {
             Transfer* d;

             int classID;
             if(m_nClass == -1)
             {
                 Transfer::BestEngine eng;

                 if(downloadTrueUploadFalse)
                     eng = Transfer::bestEngine(uris[i], Transfer::Download);
                 else
                     eng = Transfer::bestEngine(m_strDestination, Transfer::Upload);

                 if(eng.nClass < 0)
                     throw RuntimeException(tr("Couldn't autodetect transfer type for \"%1\"").arg(uris[i]));
                 else
                     classID = eng.nClass;

                 if(detectedClass == -1)
                     detectedClass = classID;
                 else if(detectedClass >= 0 && detectedClass != classID)
                     detectedClass = -2;
             }
             else
                 classID = m_nClass;

             Transfer::Mode myMode = downloadTrueUploadFalse ? Transfer::Download : Transfer::Upload;;
             d = Transfer::createInstance(myMode, classID);

             if(d == 0)
                 throw RuntimeException(tr("Failed to create a class instance."));

             listTransfers << d;

             QString source, destination;

             source = uris[i].trimmed();
             destination = m_strDestination;

             d->setUrl( (myMode == Transfer::Download) ? source : destination);
             if(!m_auth.strUser.isEmpty())
             {
                 QString& obj = (myMode == Transfer::Download) ? source : destination;

                 QUrl url = obj;
                 if(url.userInfo().isEmpty())
                 {
                     url.setUserName(m_auth.strUser);
                     url.setPassword(m_auth.strPassword);
                 }
                 obj = url.toString();
             }


             d->init(source, destination);
             d->setUserSpeedLimits(m_nDownLimit,m_nUpLimit);
         }
         if(m_bPaused)
         {
             foreach(Transfer* d, listTransfers)
                 d->setState(Transfer::Waiting);
         }
         else
         {
             foreach(Transfer* d, listTransfers)
                 d->setState(Transfer::Active);
         }
         g_queuesLock.lockForWrite();
         queue = g_queues[0];
         if(!queue)
             throw RuntimeException(tr("Internal error."));
         queue->add(listTransfers);
         g_queuesLock.unlock();
     }
     catch(const RuntimeException& e)
     {
         qDeleteAll(listTransfers);
         listTransfers.clear();
         if(!e.what().isEmpty())
         {
             qDebug() <<"Error: " + e.what();
         }
     }

     Queue::saveQueuesAsync();

}