Member Avatar for lianaconda

I'm a little confused about empty arrays. I'm supposed to write code for a function of type boolean that returns whether an array is empty or not. This function is a part of a class called Sequence, and takes no parameters. Earlier in the code, I included a typedef so that the type of array could be changed to whatever type the user needed. Inside my function, I'm trying to use an if statement to test for whether or not the array is empty, but wouldn't the if statement have to change to test for different types of arrays? Different types of arrays would have to be tested differently for being empty wouldn't they?

Also, I'm not sure how to write this class's default constructor. The name of the class is Sequence, and the default constructor is supposed to create an empty sequence. Does that mean I need to create an empty array? Every time I try to declare an array with empty brackets, the compiler tells me I need to specify a size for the array. How else do you create an empty array? Thanks!

#include <iostream>
using namespace std;

//Change the sequence to be of any type desired
typedef string ItemType;

//Default size of array
const int DEFAULT_MAX_ITEMS = 200;

class Sequence
{
public:
	Sequence();    
	// Create an empty sequence.

	bool empty() const;  
	// Return true if the sequence is empty, otherwise false

	int size() const;
	bool insert(int pos, const ItemType& value);
	bool insert(const ItemType& value);
	bool erase(int pos);
	int remove(const ItemType& value);
	bool get(int pos, ItemType& value) const;
	int find(const ItemType& value);
	void swap(Sequence& other);

private:
	ItemType seq[DEFAULT_MAX_ITEMS];
};



Sequence::Sequence()
{
       seq[DEFAULT_MAX_ITEMS];
}

bool Sequence::empty() const
{
       if (seq ?)
	return true;

       else
	return false;
}

you'll have to keep track of how many items are in the array, will be 0 when empty. Will add one when you Insert and subtract one when you Remove or Erase. Plus you already created the empty array when declaring it under the private section.

Member Avatar for lianaconda

Oh, ok, thanx!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.