Demo entry 6749584

xyylc

   

Submitted by ssd on Jun 13, 2018 at 14:22
Language: C++. Code size: 938 Bytes.

#ifndef ARRAY_CPP
#define ARRAY_CPP

#include"Array.h"

template <class T>
Array<T>::Array(int size){
	if(size<=0)
		cout<<"Invalid Array Size!!!\n\n";
	else
		ArraySize = size;
		ArrayLength = 0;
		GetArray();
}

template <class T>
void Array<T>::GetArray(void){
	array = new T[ArraySize];
	if(array == NULL) cout<<"Error!!!\n\n";
}
template <class T>
boolean Array<T>::Insert(T& x,int i){
	if(ArrayLength==ArraySize||i>ArrayLength){
		cout<<"the Array is out of range!!!\n\n";
		return FALSE;
	}
	int m;
	for(m=ArrayLength-1;m>=i;m--){
		array[m+1] = array[m];
	}
	array[i]=x;
	ArrayLength++;
	return TRUE;
}

template <class T>
boolean Array<T>::Remove(int i){
	int m;
	if(ArrayLength ==0 ) {
		cout<<"array is empty!!!\n \n";
		return FALSE;
	}
	if(i<0||i>ArrayLength-1) return FALSE;
	else
		for(m=i;m<ArrayLength-1;m++){
			array[m] = array[m+1];
		}
	ArrayLength--;
	return TRUE;
}	

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).