void main ( void ) { Deque<int> intQ; printf ( "isEmpty(1): %d\n", intQ.isEmpty ( ) ? 1 : 0 ); intQ.insertFirst ( 4 ); cout << intQ <<endl; printf ( "removeLast(4): %d\n", intQ.removeLast ( ) ); cout << intQ <<endl; intQ.insertFirst ( 5 ); intQ.insertFirst ( 12 ); intQ.insertLast ( 7 ); intQ.insertLast ( 13 ); cout << intQ <<endl; printf ( "first(12): %d\n", intQ.first ( ) ); printf ( "last(13): %d\n", intQ.last ( ) ); printf ( "size(4): %d\n", intQ.size ( ) ); printf ( "isEmpty(0): %d\n", intQ.isEmpty ( ) ? 1 : 0 ); printf ( "removeLast(13) :%d\n", intQ.removeLast ( ) ); printf ( "removeLast(7) :%d\n", intQ.removeLast ( ) ); printf ( "removeLast(5) :%d\n", intQ.removeLast ( ) ); cout << intQ <<endl; printf ( "removeFirst(12) :%d\n", intQ.removeFirst ( ) ); cout << intQ <<endl; printf ( "size(0): %d\n", intQ.size ( ) ); printf ( "isEmpty(1): %d\n", intQ.isEmpty ( ) ? 1 : 0 ); intQ.removeLast ( ); }
TEST(WTF_Deque, Remove) { Deque<int> deque; deque.append(11); deque.prepend(10); deque.append(12); deque.append(13); EXPECT_EQ(10, deque.first()); EXPECT_EQ(13, deque.last()); deque.removeLast(); EXPECT_EQ(10, deque.first()); EXPECT_EQ(12, deque.last()); deque.removeFirst(); EXPECT_EQ(11, deque.first()); EXPECT_EQ(12, deque.last()); deque.removeFirst(); EXPECT_EQ(12, deque.first()); EXPECT_EQ(12, deque.last()); deque.removeLast(); EXPECT_TRUE(deque.isEmpty()); }
/*-------------------------------------------------------------*\ | Main program | \*-------------------------------------------------------------*/ int main() { Deque D; char C; IBoolean ReadFront = True; int i; // Put all characters in the deque. // Then read it, changing the end to read from // with every character read. cout << endl << "Adding characters to the back end of the deque:" << endl; for (i = 0; String[i] != 0; i ++) { D.addAsLast(String[i]); cout << String[i]; } cout << endl << endl << "Current number of elements in the deque: " << D.numberOfElements() << endl; cout << endl << "Contents of the deque:" << endl; Print Aprinter; D.allElementsDo(Aprinter); cout << endl << endl << "Reading from the deque one element from front, one " << "from back, and so on:" << endl; while (!D.isEmpty()) { if (ReadFront) // Read from front of Deque { C = D.firstElement(); // Get the character D.removeFirst(); // Delete it from the Deque } else { C = D.lastElement(); D.removeLast(); } cout << C; ReadFront = !ReadFront; // Switch to other end of Deque } cout << endl; return(0); }
int main(int argc, char** argv) { Deque<char> a; char base_pair; while(cin >> base_pair) a.addLast(base_pair); while(!a.isEmpty()) { if(a.size() == 1) { cout << "false" << endl; return 0; } char first = a.removeFirst(); char last = a.removeLast(); switch(first) { case 'A': if(last != 'T') { cout << "false" << endl; return 0; } continue; case 'T': if(last != 'A') { cout << "false" << endl; return 0; } continue; case 'C': if(last != 'G') { cout << "false" << endl; return 0; } continue; case 'G': if(last != 'C') { cout << "false" << endl; return 0; } continue; default: cout << "false" << endl; return 0; } } cout << "true" << endl; return 0; }
static void solveMaze(void) { int x, y, offset; for (y = 0; y < height; y ++) for (x = 0; x < width; x ++) maze[y][x].visited = false; y = 0; x = 0; while (y != height - 1 || x != width - 1) { draw(x, y, true); maze[y][x].visited = true; if (!maze[y][x].right && !maze[y][x + 1].visited) { dp.addLast(offset(x + 1, y)); maze[y][x + 1].from = 1; } if (!maze[y][x].bottom && !maze[y + 1][x].visited) { dp.addLast(offset(x, y + 1)); maze[y + 1][x].from = width; } if (x > 0 && !maze[y][x - 1].right && !maze[y][x - 1].visited) { dp.addLast(offset(x - 1, y)); maze[y][x - 1].from = -1; } if (y > 0 && !maze[y - 1][x].bottom && !maze[y - 1][x].visited) { dp.addLast(offset(x, y - 1)); maze[y - 1][x].from = -width; } if (dp.getLast() == offset(x, y)) { draw(x, y, false); dp.removeLast(); } offset = dp.getLast(); x = xcoord(offset); y = ycoord(offset); } draw(width - 1, height - 1, true); }