Lesson 22 of 24

Templates: Generic Code

9 min 35 XP

Template ഒരു function-നെയോ class-നെയോ ഏത് type-നൊപ്പവും പ്രവർത്തിപ്പിക്കുന്നു. vector<int>, vector<string> എന്നിവ സ്വയം templates ആണ്!

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

Challenge

+35 XP

vector<T> അടിസ്ഥാനമാക്കിയ push, pop, top, empty എന്നിവയുള്ള template <typename T> class Stack എഴുതൂ. main()-ൽ n സംഖ്യകൾ push ചെയ്ത് print ചെയ്തുകൊണ്ട് എല്ലാം pop ചെയ്യൂ, പിന്നെ മൂന്ന് വാക്കുകളുമായി അതുതന്നെ ചെയ്യൂ. Input: 3 1 2 3 red green blue Output: 3 2 1 blue green red

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.