#ifndef RING #define RING /********************************************************** Chordalring Class A Chordal ring has no beginning or end but only a current position which is initially at node labelled 1 The chordal ring C(n,k), where n >= 5 and 2 <= k <= n/2, consists of n items, each assigned a unique number between 1 and n. Each item, labelled i, has a connection with two other items, namely, the item labelled i+1 (modulo n) and the item labelled i+k (modulo n). We will refer to connections like i to i+1 (modulo n) as short-links and connections like i to i+k (modulo n) as long-links. Note that long-links can be calculated in c++ as from i to (i+k-1)%n +1 ************************************************************/ #include #include using namespace std; struct node { int num; node * shortlink; // short link node * longlink; // long link }; class ring{ public: ring(); // Pre : none // Post : an empty ring is created ring(ring const &otherRing); void create (int n, int k); // Pre : none // Post : creates a Chordal ring of n and k // with current at node labelled 1 void move(int y); // Pre : the ring is not empty // Post : have moved the current position // y places around the ring int getCurrent()const;// Pre : the ring is not empty // Post : returns the value at the current position int size()const; // Pre : none // Post : returns the number of nodes in the ring void dumpShort()const;// Pre : ring is not empty // Post : Starting with current node and using short links // each node in chordal ring is displayed (one per line) void dumpLong()const; // Pre : ring is not empty // Post : Starting with current node and using long links // each node in chordal ring is displayed (one per line) void display()const; // Pre : ring is not empty // Post : starting from current node and using short links // each node in chordal ring is displayed in full // i.e. node, short-linked connection, long-linked connection // bool empty() const; // Pre : none // Post : returns true if ring is empty and otherwise false void remove(int x); // Pre : ring is not empty // Post : removes the node with value x from the ring. // nodes previously linked (short and long) to x will now link to x's connections // (short and long links respectively) // if current position is at x then current moved to x's short link. bool hasMember(int x) const; // Pre : none // Post : returns true if a node with value x is a member of // ring protected: void createShort(int n); // called by create to create the short linked ring void createLong(int n,int k); // called by create to create the long linked ring private: int length; node *current; }; #endif