Самоучитель C++ Part 002

Page 148

•496

Самоучитель C++ char pop() { if (tos==0) { cout « "Стек пуст"; return 0; // возврат нуля при пустом стеке } tos— ; return stckftos];

int main() // образование двух, автоматически инициализируемых, стеков stack si, s2; int i; si.push('a') ; s2.push('x') ; sl.push('b') ; s2.push('y'); si.push('c'); s2.push('z') ; for(i=0; i<3; i++) cout « "символ из стека si:" « sl.popO « "\n"; for(i=0; i<3; i++) cout « "символ из стека s2:" « s2.pop() « "\n"; return 0; }

2. finclude <iostream> ttinclude <cstring> #include <cstdlib> using namespace std; class strtype { char *p; int len; public: strtype(char *ptr) len = strlen(ptr); p=(char *) malloc(len + 1); cout « "Ошибка вьщеления памятиХп"; exit (1);


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.