Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. /*******************************************************
  2. * COMP2012 - 2014/15 Fall
  3. * Programming Assignment 2
  4. * File: List.h
  5. *******************************************************/
  6.  
  7. #ifndef _LIST_H
  8. #define _LIST_H
  9.  
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14. /* PolyNode class: the list node of a linked list
  15. representing a term in a polynomial list
  16. member variables: coef & expon
  17. */
  18. class PolyNode
  19. {
  20. public:
  21. // constructors
  22. PolyNode() { next=NULL; prev=NULL; };
  23. PolyNode(int c, int ex, int ey): coef(c), expx(ex), expy(ey) { next=NULL; prev=NULL; };
  24. PolyNode(int c, int ex, int ey, PolyNode* p, PolyNode* n): coef(c), expx(ex), expy(ey) { next=n; prev=p; };
  25.  
  26. // destructor
  27. ~PolyNode() { next=NULL; prev=NULL; };
  28.  
  29. // equal-to operator
  30. bool operator==(const PolyNode& other) const {
  31. return ((coef==other.coef)&&(expx==other.expx)&&(expy==other.expy));
  32. };
  33.  
  34. // member variables
  35. int coef;
  36. int expx;
  37. int expy;
  38.  
  39. PolyNode* prev;
  40. PolyNode* next;
  41. };
  42.  
  43. /* PolyList class: a linked list
  44. representing a polynomial
  45. */
  46. class PolyList
  47. {
  48. public:
  49. // constructor
  50. PolyList();
  51. // copy constructor
  52. PolyList(const PolyList& a);
  53. // destructor
  54. ~PolyList();
  55.  
  56. // If the linked list is empty, return true, else false
  57. bool empty() const;
  58.  
  59. // returns the number of node in the linked list
  60. int length() const;
  61.  
  62. // add a node to the end of the linked list
  63. void attachNode(PolyNode*);
  64.  
  65. // delete the first node in the linked list
  66. void deleteHead();
  67.  
  68. // Assignment operator
  69. PolyList& operator=(const PolyList& a);
  70.  
  71. // Equal-to operator
  72. bool operator==(const PolyList& a) const;
  73.  
  74. // find and return the n-th node in the linked list
  75. PolyNode* operator[](int n) const;
  76.  
  77. //get head
  78. PolyNode* getHead() const;
  79.  
  80. //get tail
  81. PolyNode* getTail()const;
  82.  
  83. //set head
  84. void setHead(PolyNode* Newhead);
  85.  
  86. //set tail
  87. void setTail(PolyNode* NewTail);
  88.  
  89.  
  90.  
  91. private:
  92. PolyNode *head;
  93. PolyNode *tail;
  94. };
  95.  
  96. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement