Proverka z 12. 11. 1998 ======================= 1. Pole pomoci zasobniku (2) ---------------------------- class CArray { public: CArray (int N); T GetAt (int index); void SetAt (int index, T x); private: CStack s1, s2; int count; }//CArray CArray::CArray (int N) { for (int i = 0; i < N; i++) s1.Push (0); count = N; }//CArray T CArray::GetAt (int index) { if ((index < count) && (index >= 0)) { T pom; for (int i = 1; i <= (count - index) - 1; i++) //index = 0 ... count - 1 s2.Push (s1.Pop); pom = s1.Pop; s1.Push (pom); for (int i = 1; i <= (count - index) - 1; i++) s1.Push (s2.Pop); return pom; }//if }//GetAt void CArray::SetAt (int index, T x) { if ((index < count) && (index >= 0)) { for (int i = 1; i <= (count - index) - 1; i++) s2.Push (s1.Pop); s1.Pop; s1.Push (x); for (int i = 1; i <= (count - index) - 1; i++) s1.Push (s2.Pop); }//if }//SetAt 2. Najit maximum v seznamu -------------------------- T Maximum () { CItem p; for (p = m_head, T pom = m_head->data; p->next != NULL; p = p->next) if (p->data > pom) pom = p->data; //T je typ, ktery se da porovnat return pom; }//Maximum 3. Test, zda je retezec ze souboru tvaru xyzCzyx (tj. symetricky podle znaku C), pr. AAABABCBABAAA -------------------------------------------------------------------------------- bool Test (FILE *s) { CStack B; char ch; bool OK = true; fopen (s, "rb"); while ((ch = getch (s)) != 'C') B.Push (ch); while (!feof (s)) if (getch (s) != B.Pop) OK = false; if (!B.Empty) OK = false; //pr. AAABABCBABA fclose (s); return OK; }//Test