template <typename T> class    Queue{ private:     unsigned int num;     int capacity;     T *elems;    //使用数组的方式存储      public:     Queue() :elems(NULL)         , num(0)         , capacity(0)     {}     ~Queue()     {         if (elems)         {             delete[] elems;             elems = NULL;         }     }     int Size()     {         return num;     }     void Push(T element)     {         checkCapacity();         if (num < capacity)         {             elems[num] = element;             num++;         }                 }     void Pop()     {         int i = 0;         while (num>i)         {             elems[i] = elems[i + 1];             i++;         }         num--;     }     bool Empty()     {         return num == 0;     }     T Back()     {         return elems[num - 1];     }     T Front()     {         return elems[0];     }     void checkCapacity()     {         if (num >= capacity)         {             capacity = capacity > 0 ? capacity * 2 : 3;             T* tmp = new T[capacity];             for (int i = 0; i < num; i++)             {                 tmp[i] = elems[i];             }             delete[] elems;             elems = tmp;         }     } }; void  test() {     Queue<int> s;     s.Push(32);     s.Push(332);     s.Push(54);     s.Push(65);     s.Push(76);     while (!s.Empty())     {         cout << s.Front() << "  ";         s.Pop();     }     cout << endl; }
点赞 评论

相关推荐

昨天 16:55
已编辑
北京工业大学 Java
211本,找日常实习的话,如果面向中厂的话,需要刷hot100么?因为之前从来没刷过,算法仅限于学校课程水平,准备3月投递简历,现在还需要背八股文,时间有些紧张,还需要刷算法题么?同时什么样的公司可以算是中厂呢?
程序员小白条:中大厂说的上名字的,必定要算法,hot100只是最基础的了,题库远不止100题捏,一般在300-400题量之间,算法=学校课程=简单题也做不出,多准备八股文和算法吧,其他项目可以放放,精刷算法就行了,花时间成长很快的
点赞 评论 收藏
分享
喵_coding:年底缺人是短视频营造出来的 而且一般说的也很宽泛 不是特指后端
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务