Advertisement
iawitm

Untitled

Mar 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. template <class T> int MyList<T>::countDifferentElements() {
  2. if (isNoEmpty())
  3. {
  4. int counter = 0;
  5.  
  6. Element *tempCar = Head;
  7. T temp = tempCar->data;
  8. for (int i = 0; i<length; i++)
  9. {
  10. if (temp <= tempCar->next->data) {
  11. temp = tempCar->next->data;
  12. tempCar = tempCar->next;
  13. }
  14. else {
  15. counter++;
  16. tempCar = tempCar->next;
  17. }
  18.  
  19. }
  20. //std::cout << "\n";
  21. return counter;
  22. }
  23. else {
  24. std::cout << "List is empty\n";
  25. return 0;
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement