Guest User

Untitled

a guest
Jan 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. banana
  2. anana
  3. nana
  4. ana
  5. na
  6. a
  7. $
  8.  
  9. #ifndef _SUFFIX_ARRAY_H
  10. #define _SUFFIX_ARRAY_H
  11.  
  12. #include<algorithm>
  13. #include<cstring>
  14. #include <stdexcept>
  15.  
  16. using namespace std;
  17. template<class T>
  18. struct comp_func
  19. {
  20. bool operator()(const T l,const T r)
  21. {
  22. return strcmp(l,r) < 0;
  23.  
  24. }
  25. };
  26. template<class T =char>
  27. class SuffixArray
  28. {
  29. int len_;
  30. T **data_;
  31.  
  32. public:
  33. T *operator[](int i)
  34. {
  35. if(i<0 || i>len_)
  36. throw std::out_of_range("Out of range errorn");
  37. return data_[i];
  38. }
  39. SuffixArray(T *str):len_(strlen(str)),data_(new T*[len_])
  40. {
  41. //len_ = strlen(str);
  42. //data_= new T*[len];
  43. for(int i =0;i<len_;++i)
  44. {
  45. data_[i] = &str[i];
  46. cout << data_[i] << endl;
  47. }
  48. std::sort(&data_[0],&data_[len_],comp_func<T *>());
  49. }
  50. void Print()
  51. {
  52. for(int i =0;i<len_;++i)
  53. {
  54. cout << data_[i] << endl;
  55. }
  56.  
  57. }
  58. };
  59.  
  60.  
  61. #endif
Add Comment
Please, Sign In to add comment