⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enhancedsafearray.h

📁 ssd5 数据结构与算法 EXAM1 敬请参考下
💻 H
字号:
//  EnhancedSafeArray.h
//  by shipengxin-063362
//  write on 2008.10.25

#ifndef EnhancedSafeArray_H
#define EnhancedSafeArray_H

using namespace std;

#include"safearray.h"

template<class T>
class EnhancedSafeArray  :  public SafeArray<T>{     // class EnhancedSafeArray
 
public:             // member  function
	EnhancedSafeArray(void);
	EnhancedSafeArray(int);
	EnhancedSafeArray(EnhancedSafeArray<T>& array);
	int size(void) const;
	EnhancedSafeArray<T>& operator =(EnhancedSafeArray<T>& array);
	bool operator ==(EnhancedSafeArray<T>& array);
};



template<class T>
EnhancedSafeArray<T>::EnhancedSafeArray(void) : SafeArray<T>() {}   //defualt constructor

 

template<class T>
EnhancedSafeArray<T>::EnhancedSafeArray(int count) : SafeArray<T>(count) {}    //single-parameter constructor



template<class T>
EnhancedSafeArray<T>::EnhancedSafeArray(EnhancedSafeArray<T>& array){    //Copy constructor


	count = array.count;    
	storage = new T[count];     // creat a new memory
	for(int i=0; i<count; i++)   // copy the instance
	{
	
		storage[i] = array.storage[i];

	}

}




template<class T>
int EnhancedSafeArray<T>::size(void) const {       //function which return the the number of elements stored .

	return count;

}



template<class T>
EnhancedSafeArray<T>& EnhancedSafeArray<T>::operator=(EnhancedSafeArray<T>& array) {  // the function to copy one instance to another.

	delete [] storage;     // free the old memory
	count=array.count;
	storage=new T[count];   // creat a new memory
	for(int i = 0; i < count; i++)        // copy the instance
	{
		storage[i] = array.storage[i];
	}

	return * this;
}



template<class T>
bool EnhancedSafeArray<T>::operator==(EnhancedSafeArray<T>& array){    //the function to judge whether the two instance
                                                                       //are equal,then return a bool value.
   
	if (count != array.count)      // if count is not equal ,return false.
		return false;
	int i=0;
	while(i>=0&&i<array.count)    // if one value is not equal ,return false.
	{
		while(storage[i] != array.storage[i])
		return false;
		i++;
	}
	return true;           // equal ,return true.
	
}

#endif  // EnhancedSafeArray_H:~

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -