static void testDeque() { Deque <int> deq = new Deque <int>(); deq.AddFront(1); deq.AddFront(2); deq.AddFront(3); deq.AddTail(4); deq.AddTail(5); Console.WriteLine("размер" + deq.Size()); while (deq.Size() > 0) { Console.WriteLine(deq.RemoveFront()); Console.WriteLine("размер " + deq.Size()); Console.WriteLine(deq.RemoveTail()); Console.WriteLine("размер " + deq.Size()); } }
public bool isPalindrom(string str) { // проверка, является ли число палиндромом Deque <char> temp = new Deque <char>(); for (int i = 0; i < str.Length; i++) { temp.AddTail(str[i]); } for (int i = 0; i < str.Length % 2; i++) { if (temp.RemoveFront() != temp.RemoveTail()) { return(false); } } return(true); }
public static bool pallindrom(String str) { Deque <char> deq = new Deque <Char>(); for (int i = str.Length - 1; i >= 0; i--) { if (str[i] != ' ') { deq.AddTail(str[i]); } } while (deq.Size() / 2 > 0) { if (deq.RemoveTail() != deq.RemoveFront()) { return(false); } } return(true); }
static void TestDeque() { Console.WriteLine("test deque"); Deque <int> deque = new Deque <int>(); int i = 1; Console.WriteLine("add in front"); for (; i <= 10; i++) { deque.AddFront(i); Console.Write(i + " "); } Console.WriteLine(); Console.WriteLine("size after add in front = " + deque.Size()); Console.WriteLine(); for (; i <= 20; i++) { deque.AddTail(i); Console.Write(i + " "); } Console.WriteLine(); Console.WriteLine("size after add in tail = " + deque.Size()); Console.WriteLine(); Console.WriteLine("remove from front"); for (int j = 0; j < 5; j++) { Console.Write(deque.RemoveFront() + " "); } Console.WriteLine(); Console.WriteLine("size after remove from front = " + deque.Size()); Console.WriteLine(); Console.WriteLine("remove from tail"); for (int j = 0; j < 5; j++) { Console.Write(deque.RemoveTail() + " "); } Console.WriteLine(); Console.WriteLine("size after remove from tail = " + deque.Size()); Console.WriteLine(); Console.WriteLine("remote from front"); while (deque.Size() != 0) { Console.Write(deque.RemoveFront() + " "); } Console.WriteLine(); Console.WriteLine("size after remove from tail = " + deque.Size()); Console.WriteLine(); Console.WriteLine("try to remove from tail, deque size = " + deque.Size()); int result = deque.RemoveTail(); Console.WriteLine("result = " + result); Console.WriteLine("try to remove from front, deque size = " + deque.Size()); result = deque.RemoveFront(); Console.WriteLine("result = " + result); Console.WriteLine(new string('=', 50)); }