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.