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:

  1. Johnathan Teo DCPE 2A/05November 8, 2010 at 11:24 AM

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

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

    ReplyDelete
  3. Bernard Chew DCPE 2A05November 8, 2010 at 11:34 AM

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

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

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

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

    ReplyDelete
  7. http://snipt.net/embed/abf4caf613e737a1edde7f4c1e2a2ab2

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

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

    ReplyDelete
  10. @guys,
    keep the code coming in~~!!~~

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

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

    ReplyDelete
  13. http://snipt.net/asdsieg/function

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

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

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

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

    ReplyDelete
  18. muhammad ramadhan dcpe/2b/03November 9, 2010 at 12:12 PM

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

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

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

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

    ReplyDelete
  22. http://snipt.net/bigshow/week42

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


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

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

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

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

    ReplyDelete