Monday, November 8, 2010

[DSA] template class

Template, as the name suggested is a standard or generic way/form we could use for creating different output. For an example, you would ask for a report template from your senior so that you more or less know how what is expected from you.

One of the benefits of programming through a template, it reduces the effort to recode the same function/class but pass in a different variable type. Our good friend the STL Algorithms is the best example of programming template. Imagine the sort() function need to be rewrite again and again and again for each type of variable...............

I strongly do not advocate of getting report from other people and change it to your name. That is not template nor referencing. It is called plagiarism.

A function template or class template, beside used with primary variable, eg int, char, double. It can be used with data structures too. As usual, it is possible to pass in more then 1 parameter of the same or different variable type to the function template or class template.

reference the code below. NOTE: The Code is NOT COMPLETE you need to fix it before you could use it.

Q1. What does both of the function trying to do??? Is there a way to generalize it without repeating the "same" code?
Q2. Populate the given code with a template function that will double each number stored as elements in the data structure. Is it possible to double a char or a string stored in the data structure??

//===CHALLENGE==> HEROES ONLY=====//
Q3. Write a template function reverselist() that could take in a list display the content of the list and store the contents of the list on to a stack and later display the content of the stack.
Q4. Is there a more efficient way to create a test for a palindrome????



26 comments:

Johnathan Teo DCPE 2A/05 said...

http://snipt.net/sgxbuster/rect-template

Afiq DCPE 2A05 said...

http://snipt.net/puteraafiq/template-15/

Bernard Chew DCPE 2A05 said...

http://snipt.net/BernardChew/using-template

Rui Wei(2B05) said...

http://snipt.net/RuiWei/template-16

Danny 2B/05 said...

http://snipt.net/dannygsy/danny-2b05-1

Danny 2B/05 said...

http://snipt.net/dannygsy/danny-2b05-1

Douglas said...

http://snipt.net/embed/abf4caf613e737a1edde7f4c1e2a2ab2

Edwin 2B05 said...

http://snipt.net/edwinraja/using-templates-to-calculate-area-and-volume

Douglas said...

http://snipt.net/crazygameazz/template-17

sjteo said...

@guys,
keep the code coming in~~!!~~

alvin dcpe/ft/2b/03 said...

http://snipt.net/alvinthen/9-nov-2010?key=6d494170494528ed64be30931ce0356b

Yi Wei said...

http://snipt.net/jellybanana/week-4-functions-practice

yao de DCPE 2B03 said...

http://snipt.net/asdsieg/function

Felix (DCPE 2b03) said...

http://snipt.net/UJuzGtJacked/areavoltemplate?key=a99ceebd7fa618dc79a2fe4eb7c805f0

XuZhou said...

http://snipt.net/bigshow/week-4

alvin dcpe/ft/2b/03 said...

http://snipt.net/alvinthen/9-nov-2010-template?key=97d11e9b8917ea0b2e9533bc93e60079

Felix (DCPE 2b03) said...

http://snipt.net/UJuzGtJacked/areavoltemplatemodified/?key=93d4a5c6725f013d3c9e5584f3c3a625

muhammad ramadhan dcpe/2b/03 said...

http://snipt.net/Wizardgenesis/template-example/?key=f583ef2afaf76ea59e1a8c349aa2f550

Yi Wei said...

http://snipt.net/jellybanana/week-4-template-functions

yao de DCPE 2B03 said...

http://snipt.net/asdsieg/template-18

Sathis 2B03 said...

http://snipt.net/Stish/templates-2

XuZhou said...

http://snipt.net/bigshow/week42

Qi Hao(DCPE/2B/03) said...

http://snipt.net/sa198/qi-haodcpe2b03-3/?key=9307d4749ff6004a5ad37015b25a1dbf


http://snipt.net/sa198/qi-haodcpe2b03-4/?key=ac0dc38fd5b08ed2dac7834cd39d44d9

Li Xiaofei 2B03 said...

http://snipt.net/xiaofei/use-tem-to-cal-a-and-v

heng gnee dcpe/ft/2b/03 said...

http://snipt.net/hengnee/sorry-for-sending-in-so-late

Wang Liang said...

http://snipt.net/J0k3r/tag/template