Exemplo n.º 1
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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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.º 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();
    }
}
int main() {
    MyQueue queue;
    
    queue.enqueue(1);
    queue.enqueue(2);
    queue.dequeue();
    queue.enqueue(3);
    
    printf("Values in queue: ");
    
    while (!queue.empty()) {
        printf("%d ", queue.dequeue());
    }
    
    printf("\n");

    return 0;
}
Exemplo n.º 6
0
void Graph<Tv, Te>::BFS(int v, int &clock){
    MyQueue<int> Q; //引入辅助队列
    status(v) = DISCOVERED;
    Q.enqueue(v);  //初始化起点
    while(!Q.empty()){  //在Q变空之前,不断
        int v = Q.dequeue(); dTime(v) = ++clock;  //取出队首顶点v
        for(int u = firstNbr(v); -1 < u; u = nextNbr(v, u))  //枚举v的所有邻居
            if(UNDISCOVERED == status(u)){  //尚未被发现,则
                status(u) = DISCOVERED;  //设置为已发现
                Q.enqueue(u);   //并且将该顶点入队
                type(v, u) = TREE;
                parent(u) = v;   //引入树边拓展支撑树
            }else{
                type(v, u) = CROSS; //将(v,u)归类于跨边
            }
        status(v) = VISITED;  //至此,当前节点访问完毕
    }
}
Exemplo n.º 7
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;
    }
}
Exemplo n.º 8
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.º 9
0
void test(){
	
	int seq [6] = {0,0,0,0,0,0};
	Board * start ;
	Board * current;
	int record=0;
	initialize();
	int step_size =0 ;
	while(gen_next_recur(seq)){
		record ++ ;
		//if(record < 20)
		//	continue;
		print_seq(seq);
		for(int piindex = 0 ; piindex < PATTERN_NUM ;piindex++){
			start = new Board();
			start->init_with_sequence(seq,piindex);
			open_list.push(start);
			step_size =0;	
			
			while(!open_list.empty()){
				current = open_list.top();
				open_list.pop();
				close_list.push(current);
				//current->print();
				if(current->is_goal()){
					printf("Goal Found for pattern %d , step =%d\n",piindex,current->step);
					//current->print();
					break;
				}
				if(step_size<current->step){
					step_size = current->step;
					printf("%d\n",step_size);
				}
				for(int tile_id =0 ;tile_id < PATTERN_SIZE ;tile_id++){
					for (int direc =0; direc < 4 ;direc++){
						Board * tmp = current->gen_board(tile_id,direc);
						if(tmp){
							if(!close_list.exist(tmp)&&!open_list.exist(tmp)){	
								open_list.push(tmp);
							}else
								delete tmp;
						}
					}
				}
			}

			write_db(seq,piindex,current->step);
			
			while(!open_list.empty()){
				current = open_list.top(); 
				open_list.pop();
				delete current;
			}
			
			while(!close_list.empty()){
				current = close_list.top();
				close_list.pop();
				delete current;
			}
			//break;
		}
		//break;
	}
}