Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "sequence2.h"
- using namespace CISP430_A2;
- using namespace std;
- typedef double value_type;
- typedef size_t size_type;
- // COPY CONSTRUCTOR
- sequence::sequence(const sequence& entry)
- {
- for(int i=0;i<capacity;i++)
- data[i]=entry.data[i];
- used=entry.used;
- capacity=entry.capacity;
- current_index=entry.current_index;
- }
- // Library facilities used: cstdlib
- // MODIFICATION MEMBER FUNCTIONS
- void sequence::start()
- {
- current_index = 0;
- }
- void sequence::advance()
- {
- if (is_item()==true)
- current_index += 1;
- }
- void sequence::insert(const value_type& entry)
- {
- if (current_index==0)
- {
- for(int i=capacity;i>=0;i--)
- data[i]=data[i-1];
- }
- if (size() == 1)
- data[current_index]= entry;
- else if(size() < CAPACITY)
- data[current_index-1] = entry;
- else
- capacity*=1.1;
- ++used;
- }
- void sequence::attach(const value_type& entry)
- {
- if (size() == 1)
- data[current_index]= entry;
- else if(size() < CAPACITY)
- data[current_index+1] = entry;
- else
- capacity*=1.1;
- ++used;
- }
- void sequence::remove_current()
- {
- if (is_item()==true)
- {
- for (int i=current_index+1;i<used;++i)
- data[i-1]=data[i];
- --used;
- }
- }
- void sequence::resize(size_type new_capacity)
- {
- if (new_capacity > size())
- capacity = new_capacity;
- }
- void sequence::operator =(const sequence& entry)
- {
- for(int i=0;i<capacity;i++)
- data[i]=entry.data[i];
- used=entry.used;
- capacity=entry.capacity;
- current_index=entry.current_index;
- }
- // CONSTANT MEMBER FUNCTIONS
- size_type sequence::size() const
- {
- return used;
- }
- bool sequence::is_item() const
- {
- if (current_index >= 0 && current_index <= capacity)
- return true;
- else
- return false;
- }
- value_type sequence::current() const
- {
- if (is_item()== true)
- return data[current_index];
- else
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement