Exemplo n.º 1
0
/*
 *  Repaint silhouette in color of background
 *
 *  @param  point Extreme point of silhouette
 *  @param  imageMatrix 2d array that contains color's
 *  @param  width The width of the image
 *  @param  height The height of the image
 *  @param  backgroundColor Variable that indicate background color
 */
void SilCounter::fillSilhouette(QPoint &point, int **imageMatrix, int width, int height, int backgroundColor){
    // queue that store all point neighbours, with silhouette color
    MyQueue<QPoint> queueOfPoints;

    // repaint point in background color to prevent it from re-adding to the queue from cycle
    imageMatrix[point.y()][point.x()] = backgroundColor;
    queueOfPoints.push(point);\

    // walk throw all point neigbours with silhouette color
    while(queueOfPoints.size()){

        // temporary variable for poin from queue
        QPoint temp = queueOfPoints.front();
        int x = temp.x();
        int y = temp.y();
        queueOfPoints.pop();\

        // walk throw all point neigbours with silhouette color repaint them and adding to the queue
        for(int i = -1; i <= 1; i++){
            for(int j = -1; j <= 1; j++){
                if( (0 <= x + i) && (x + i < width) && (0 <= y + j) && (y + j < height) && (imageMatrix[y + j][x + i] != backgroundColor)){
                    imageMatrix[y + j][x + i] = backgroundColor;
                    queueOfPoints.push(QPoint(x + i,y + j));
                }
            }
        }
    }
}
Exemplo n.º 2
0
int main() {
    MyQueue<int> que;
    que.push(1);
    que.push(2);
    que.push(3);
    que.push(4);
    while(que.size() != 0) {
        cout<<que.pop()<<" ";
    }
    que.push(5);
    que.push(6);
    while(que.size() != 0) {
        cout<<que.pop()<<" ";
    }
    cout<<endl;
    que.pop();
    return 0;
}
Exemplo n.º 3
0
int main(int argc, char** argv)
{
    MyQueue<int> myQ;
    myQ.enqueue(1);
    myQ.enqueue(2);
    myQ.enqueue(3);
    myQ.enqueue(4);
    while (myQ.size() > 2) {
        cout << "Front of MyQueue object: " << myQ.front() << endl;
        myQ.dequeue();
    }
    myQ.enqueue(5);
    myQ.enqueue(6);
    while (myQ.size() > 0) {
        cout << "Front of MyQueue object: " << myQ.front() << endl;
        myQ.dequeue();
    }

    return 0;
}
Exemplo n.º 4
0
int main() {
    MyQueue<int> st;
    int k;
    for (int i = 0; i < 100; i++)
        st.append(i);
    std::cout << st.size() << std::endl << std::endl;
    for (int i = 0; i < 10; i++)
        st.serve();
    st.retrieve(k);
    std::cout << k << std::endl << std::endl;
    std::cout << st.size() << std::endl << std::endl;
    for (int i = 0; i < 10; i++)
        st.append(i);
    std::cout << st.size() << std::endl << std::endl;
    while (!st.empty()) {
        st.retrieve_and_serve(k);
        std::cout << k << std::endl;
    }
    std::cout << st.size() << std::endl << std::endl;
    return 0;
}
Exemplo n.º 5
0
void buildMagicCubeForest(MyQueue bucket) {
    MagicCubeTree tree;
    
    while (!bucket.empty()) {
        tree = MagicCubeTree(bucket.front().getHistory(), bucket.front().getCompress());
        tree.setMagicCubeTree();
        if (tree.getSizeOfBranches() != 0) {
            bucket.pushs(tree);
        }
        cout << tree.getMyself().getHistory() << endl;
        cout <<"bucket "<<bucket.size() << endl;
        bucket.pop();
    }
}
Exemplo n.º 6
0
int main(void)
{
    MyQueue<int> list;
    
    list.enqueue(1);
    list.enqueue(2);

    cout << "Size = " << list.size() << endl;
    cout << "Dequeue => " << list.dequeue() << endl;
    cout << "Peek => " << list.peek() << endl;
    
    list.clear();
    
    if (list.isEmpty())
        list.enqueue(3);
    
    return 0;
}
Exemplo n.º 7
0
int main()
{
	MyQueue *q;
	int n, m;
	int i;
	char s[20];
	int val;

	while (scanf("%d%d", &n, &m) == 2) {
		q = new MyQueue(m);
		for (i = 0; i < n; ++i) {
			scanf("%s", s);
			if (strcmp(s, "Push") == 0) {
				scanf("%d", &val);
				if (q->full()) {
					printf("failed\n");
				} else {
					q->push(val);
				}
			} else if (strcmp(s, "Pop") == 0) {
				if (q->empty()) {
					printf("failed\n");
				} else {
					q->pop();
				}
			} else if (strcmp(s, "Query") == 0) {
				scanf("%d", &val);
				if (val < 1 || val > q->size()) {
					printf("failed\n");
				} else {
					printf("%d\n", q->front(val));
				}
			} else if (strcmp(s, "Isempty") == 0) {
				printf(q->empty() ? "yes\n" : "no\n");
			} else if (strcmp(s, "Isfull") == 0) {
				printf(q->full() ? "yes\n" : "no\n");
			}
		}
		delete q;
	}

	return 0;
}
Exemplo n.º 8
0
int main() {
    MyQueue mq;
    mq.push(1);
    mq.push(2);
    mq.push(3);
    mq.push(4);
    mq.push(5);
    mq.push(6);

    cout << "size: " << mq.size() << endl;

    cout << "peek: " << mq.peek() << endl;
    cout << mq.pop() << endl;
    cout << mq.pop() << endl;
    mq.push(100);
    cout << mq.pop() << endl;
    cout << mq.pop() << endl;
    cout << mq.pop() << endl;
    cout << mq.pop() << endl;
    cout << mq.pop() << endl;
}
Exemplo n.º 9
0
void Test_7_QueueWithTwoStack()
{
	MyQueue q;
	try
	{
		cout << "top is " << q.top() << endl;
		cout << "size is " << q.size() << endl;
	}
	catch (exception &e)
	{
		cout << e.what() << endl;
	}

	q.push(1);
	try
	{
		cout << "top is " << q.top() << endl;
		cout << "size is " << q.size() << endl;
	}
	catch (exception &e)
	{
		cout << e.what() << endl;
	}
	q.push(2);
	q.push(3);
	try
	{
		cout << "top is " << q.top() << endl;
		cout << "size is " << q.size() << endl;
	}
	catch (exception &e)
	{
		cout << e.what() << endl;
	}

	try
	{
		q.pop();
		cout << "top is " << q.top() << endl;
		cout << "size is " << q.size() << endl;
	}
	catch (exception &e)
	{
		cout << e.what() << endl;
	}

	try
	{
		q.pop();
		cout << "top is " << q.top() << endl;
		cout << "size is " << q.size() << endl;
	}
	catch (exception &e)
	{
		cout << e.what() << endl;
	}

	try
	{
		q.pop();
		cout << "top is " << q.top() << endl;
		cout << "size is " << q.size() << endl;
	}
	catch (exception &e)
	{
		cout << e.what() << endl;
	}

	try
	{
		q.pop();
		cout << "top is " << q.top() << endl;
		cout << "size is " << q.size() << endl;
	}
	catch (exception &e)
	{
		cout << e.what() << endl;
	}
}