{"id":220,"date":"2012-04-23T14:20:04","date_gmt":"2012-04-23T13:20:04","guid":{"rendered":"http:\/\/csipet.web.elte.hu\/?p=220"},"modified":"2012-04-23T14:20:04","modified_gmt":"2012-04-23T13:20:04","slug":"11-ora-2","status":"publish","type":"post","link":"https:\/\/peter.csonka.hu\/hu\/blog\/2012\/04\/11-ora-2\/","title":{"rendered":"11. \u00f3ra"},"content":{"rendered":"<p><a href=\"https:\/\/docs.google.com\/document\/d\/19Nl9-33m5tZruWxhdzQ9anPBUJcXwU0BxqEnrvcpsjM\/edit\">https:\/\/docs.google.com\/document\/d\/19Nl9-33m5tZruWxhdzQ9anPBUJcXwU0BxqEnrvcpsjM\/edit<\/a><\/p>\n<p>main:<\/p>\n<pre lang=\"c\" line=\"1\">\n#include <iostream>\n#include \"verem.h\"\n\nusing namespace std;\n\nint main () {\n\tStack<int> verem;\n\tverem.push(1);\n\tcout << verem.top() <<endl;\n\treturn 0;\n}\n<\/pre>\n<p>verem.h:<\/p>\n<pre lang=\"c\" line=\"1\">\n#ifndef VEREM_H_INCLUDED\n#define VEREM_H_INCLUDED\n\n#define DEFAULT_SIZE 5\ntemplate <typename t>\nclass Stack {\npublic:\n\tStack(int=DEFAULT_SIZE);\n\n\tvoid push(t);\n\tt pop();\n\tt top()const {return _array[_top];}\n\n\tint size()const {return _top;}\n\tint maxSize()const {return _max;}\n\n\tvoid clear();\n\tbool isEmpty()const{return -1==_top;}\n\n\tStack(const Stack&);\n\tStack& operator = (const Stack&);\n\t~Stack();\nprivate:\n\tt* _array;\n\tint _top;\n\tint _max;\n};\n\n#endif \/\/ VEREM_H_INCLUDED\n\nusing std::cout;\nusing std::endl;\n\ntemplate <typename t>\nStack<t>::Stack(int max_):_top(-1),_max(max_)\n{\n\tif(max_>0)\n    \t_array=new t[max_];\n\telse\n\t{\n    \tcout<<\"The max size must be >0!!\"<<endl;\n    \t_array=new t[DEFAULT_SIZE];\n    \t_max=DEFAULT_SIZE;\n\t}\n}\n\ntemplate <typename t>\nvoid Stack<t>::push(t item_)\n{\n\tif(_top!=_max)\n    \t_array[++_top]=item_;\n\telse\n    \tcout<<\"The stack is full!!\"<<endl;\/\/Iparban is haszn\u00e1lt megold\u00e1s: throw \"full\"; az \"xy\" helyett valami exception lesz\u00e1rmazotatt szoktak dobni.\n}\n\ntemplate <typename t>\nt Stack<t>::pop()\n{\n\tif(_top!=-1)\n    \treturn _array[_top--];\n\telse\n    \tcout<<\"The stack is empty\"<<endl;\/\/Iparban is haszn\u00e1lt megold\u00e1s: throw \"empty\"; az \"xy\" helyett valami exception lesz\u00e1rmazotatt szoktak dobni.\n}\n\ntemplate <typename t>\nvoid Stack<t>::clear()\n{\n\tdelete[] _array;\n\t_array=new t[_max];\n\t_top=-1;\n}\n\ntemplate <typename t>\n\/\/deep copy meg kell \u00edrni mivel az _array dinamikusan van foglalva\nStack<t>::Stack(const Stack& stack_)\n{\n\t_max=stack_._max;\n\t_top=stack_._top;\n\t_array=new t[_max];\n\tfor(int i=0;i<=_top;++i)\n    \t_array[i]=stack_._array[i];\n\n}\n\ntemplate <typename t>\nStack<t>& Stack<t>::operator = (const Stack& stack_)\n{\n \tdelete[] _array;\/\/ Az\u00e9rt kell mivel itt m\u00e1r l\u00e9tezik az objektu, a copy konstruktorn\u00e1l feljebb m\u00e9g nem l\u00e9tezik, hanem akkor j\u00f6n l\u00e9tre\n\t_max=stack_._max;\n\t_top=stack_._top;\n\t_array=new t[_max];\n\tfor(int i=0;i<=_top;++i)\n    \t_array[i]=stack_._array[i];\n\treturn *this;\n}\n\ntemplate <typename t>\nStack<t>::~Stack()\n{\n\tdelete[] _array;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/docs.google.com\/document\/d\/19Nl9-33m5tZruWxhdzQ9anPBUJcXwU0BxqEnrvcpsjM\/edit main: #include #include &#8222;verem.h&#8221; using namespace std; int main () { Stack verem; verem.push(1); cout<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[65],"tags":[],"class_list":["post-220","post","type-post","status-publish","format-standard","hentry","category-programozas-nyelvek-c"],"_links":{"self":[{"href":"https:\/\/peter.csonka.hu\/hu\/wp-json\/wp\/v2\/posts\/220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peter.csonka.hu\/hu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peter.csonka.hu\/hu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peter.csonka.hu\/hu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peter.csonka.hu\/hu\/wp-json\/wp\/v2\/comments?post=220"}],"version-history":[{"count":0,"href":"https:\/\/peter.csonka.hu\/hu\/wp-json\/wp\/v2\/posts\/220\/revisions"}],"wp:attachment":[{"href":"https:\/\/peter.csonka.hu\/hu\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peter.csonka.hu\/hu\/wp-json\/wp\/v2\/categories?post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peter.csonka.hu\/hu\/wp-json\/wp\/v2\/tags?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}