Exemplo n.º 1
0
TEST(D_QueueViaStacksTest, Test2)
{
	std::string output;
	testing::internal::CaptureStdout();

	MyQueue<int> mq;
	try
	{
		mq.enqueue(1);
		mq.dequeue();
		mq.enqueue(2);
		mq.dequeue();
		mq.enqueue(3);
		mq.dequeue();
		mq.enqueue(4);
		mq.dequeue();
		mq.enqueue(5);
		std::cout << "\n Front element in queue is " << mq.front();
		mq.dequeue();
		mq.enqueue(6);
		std::cout << "\n Front element in queue is " << mq.front();
	}
	catch (std::exception e)
	{
		std::cout << e.what();
	}

	output = testing::internal::GetCapturedStdout();

	EXPECT_EQ(1, 1);

}
Exemplo n.º 2
0
int main()
{
    MyQueue<int> queue;
    queue.enqueue(1);
    queue.enqueue(2);
    queue.enqueue(3);
    if (!queue.empty()) {
        std::cout << queue.front() << std::endl;
        std::cout << queue.back() << std::endl;
    }
    queue.dequeue();
    queue.enqueue(4);
    if (!queue.empty()) {
        std::cout << queue.front() << std::endl;
        std::cout << queue.back() << std::endl;
    }
    queue.enqueue(5);
    queue.dequeue();
    if (!queue.empty()) {
        std::cout << queue.front() << std::endl;
        std::cout << queue.back() << std::endl;
    }
    queue.dequeue();
    queue.dequeue();
    queue.dequeue();
    if (!queue.empty()) {
        std::cout << queue.front() << std::endl;
        std::cout << queue.back() << std::endl;
    }
    queue.dequeue();
    queue.dequeue();
    return 0;
}
int main (char *argv[], int argc) {
	MyQueue q;
	q.push(1);
	q.push(2);
	q.push(3);
	cout << q.front() << endl;
	cout << q.back() << endl;
	q.pop();
	cout << q.front() << endl;
	cout << q.back() << endl;
	return 0;
}
Exemplo n.º 4
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.º 5
0
int main(int argc, char const *argv[])
{
	MyQueue<int> q;
	for(int i = 0; i < 10; i++)
	{
		q.push(i);
	}
	cout<<q.front()<<" "<<q.rear()<<endl;
	q.pop();
	cout<<q.front()<<" "<<q.rear()<<endl;
	q.push(11);
	cout<<q.front()<<" "<<q.rear()<<endl;
	return 0;
}
Exemplo n.º 6
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.º 7
0
void test2()
{
    MyQueue<int> que;

    for (int i = 0; i < 5; i++)
    {
        que.push(i);
    }

    //empty()

    cout << "empty = " << que.empty() << endl;


//
    //pop()
    que.pop();
    que.pop();
    que.pop();


    //back()
    int temp_back = que.back();
    cout << "temp_back = " << temp_back << endl;

    //front()
    int temp_front = que.front();
    cout << "temp_front = " << temp_front << endl;
}
int main(){

  MyStack<int> a;
  MyQueue<int> c;
  
  a.push(4);
  a.push(5);
  cout << a.top() << endl;
  a.pop();
  cout << a.top() << endl;
  
  c.enqueue(4);
  c.enqueue(5);
  cout << c.front() << endl;
  c.dequeue();
  cout << c.front() << endl;
}
Exemplo n.º 9
0
int main(int argc,char*argv[]){
	MyQueue mq;
	for(int i=1;i<=5;++i)
		mq.push(i);
	for(int i=1;i<=6;++i){
		cout << "front: " << mq.front() << endl;
		cout << "back: " << mq.back() << endl;
		mq.pop();
	}
	return 0;
}
Exemplo n.º 10
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.º 11
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.º 12
0
/* This function takes filled grid with boolean values. Black points are marked
 * as true, other - as false. If number of neighbour black points more than
 * const MIN_SILOUETTES_SIZE, such area is marked is silouette.
 * Function returns the number of silouettes.
 */
void detectingSilouettes(Grid<bool> &pixels) {
    int countBlackPoints;
    while (!checkAllNeighbours.empty()) {
        Points buffer = checkAllNeighbours.front();
        checkAllNeighbours.pop();
        for (int x = buffer.column - 1; x <= buffer.column + 1; x++) {
            for (int y = buffer.row - 1; y <= buffer.row + 1; y++) {
                if (pixels.inBounds(x, y) && pixels.get(x, y) == true) {
                    countBlackPoints++;
                    Points blackPoint = makePoint(x, y);
                    pixels.set(x, y, false);
                    checkAllNeighbours.push(blackPoint);
                }
            }
        }
    }
    if (countBlackPoints >= MIN_SILOUETTES_SIZE) {
        countSilouettes++;
        countBlackPoints = 0;
    }
}