#include <iostream>
#include <fstream>
#include <string>

using namespace std;

template <class T>
class Queue {
private:
	T data[100];
	int back; // top in stack
	const static int front = 0;
	void shift() {
		for( int i=0; i< back; i++ )
			data[i] = data[i+1];
		back--;
	}
public:
	Queue() { back = -1; }; // same as stack
	void enQ(T v) { data[++back] = v; } // same as stack
	T deQ() { T val = data[front]; shift(); return val; }
	int count() { return back+1; } // same as stack
	T getFront() { return data[front]; }
	T getBack() { return data[back]; }
	bool isEmpty() { return (back==-1); } // same as stack
	void clear() { back = -1; } // same as stack
	void show() { for(int i=0; i <= back; i++ ) {cout << data[i] << " ";} cout << endl; }
};

int main()
{
	Queue<string> menQ, womenQ;

	// Read data from file
	ifstream infile("people.txt");
	string sex, name;
	while( !infile.eof() ) {
		getline( infile, sex, ',' );
		getline( infile, name );
		if( sex == "M" )
			menQ.enQ( name );
		else
			womenQ.enQ( name);
		// (sex == "M") ? menQ.enQ(name) : womenQ.enQ(name);
		//((sex == "M") ? menQ : womenQ ).enQ(name);
	}

	while( !menQ.isEmpty() && !womenQ.isEmpty() ) {
		cout << menQ.deQ() << " dancing with " << womenQ.deQ() << endl;
	}

	if( menQ.isEmpty() ) {
		cout << "There are women left: " << womenQ.count() << endl;
		cout << "First waiting for partner: " << womenQ.getFront() << endl;
	}

	if( womenQ.isEmpty() ) {
		cout << "There are men left: " << menQ.count() << endl;
		cout << "First waiting for partner: " << menQ.getFront() << endl;
	}

	infile.close();

	system("pause");

}