展开全部
#include <iostream>
using namespace std;
template <class Type>
class list
{
private:
int maxSize;
int size;
Type *data;
public:
list(int _maxSize = 5)
{
maxSize = _maxSize;
size = 0;
data = new Type[maxSize];
}
bool Append( Type val)
{
if(size < maxSize)
{
data[size++] = val;
return true;
}
return false;
}
Type GetElem( int pos )
{
if(pos < size && pos > -1)
{
return data[pos];
}
else
{
exit(1);
}
}
void Display()
{
int i;
for(i=0; i<size; i++)
{
cout << data[i] << " ";
}
cout << endl;
}
};
int main()
{
list<int> *l = new list();
int i;
while(cin >> i)
{
if(!l->Append(i)) break;
}
l->Display();
return 0;
}
using namespace std;
template <class Type>
class list
{
private:
int maxSize;
int size;
Type *data;
public:
list(int _maxSize = 5)
{
maxSize = _maxSize;
size = 0;
data = new Type[maxSize];
}
bool Append( Type val)
{
if(size < maxSize)
{
data[size++] = val;
return true;
}
return false;
}
Type GetElem( int pos )
{
if(pos < size && pos > -1)
{
return data[pos];
}
else
{
exit(1);
}
}
void Display()
{
int i;
for(i=0; i<size; i++)
{
cout << data[i] << " ";
}
cout << endl;
}
};
int main()
{
list<int> *l = new list();
int i;
while(cin >> i)
{
if(!l->Append(i)) break;
}
l->Display();
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
using namespace std;
template <class Type>
class list
{
private:
int maxSize;
int size;
Type *data;
public:
list(int _maxSize = 5)
{
maxSize = _maxSize;
size = 0;
data = new Type[maxSize];
}
bool Append( Type val)
{
if(size < maxSize)
{
data[size++] = val;
return true;
}
return false;
}
Type GetElem( int pos )
{
if(pos < size && pos > -1)
{
return data[pos];
}
else
{
exit(1);
}
}
void Display()
{
int i;
for(i=0; i<size; i++)
{
cout << data[i] << " ";
}
cout << endl;
}
};
int main()
{
list<int> *l = new list();
int i;
while(cin >> i)
{
if(!l->Append(i)) break;
}
l->Display();
return 0;
}
using namespace std;
template <class Type>
class list
{
private:
int maxSize;
int size;
Type *data;
public:
list(int _maxSize = 5)
{
maxSize = _maxSize;
size = 0;
data = new Type[maxSize];
}
bool Append( Type val)
{
if(size < maxSize)
{
data[size++] = val;
return true;
}
return false;
}
Type GetElem( int pos )
{
if(pos < size && pos > -1)
{
return data[pos];
}
else
{
exit(1);
}
}
void Display()
{
int i;
for(i=0; i<size; i++)
{
cout << data[i] << " ";
}
cout << endl;
}
};
int main()
{
list<int> *l = new list();
int i;
while(cin >> i)
{
if(!l->Append(i)) break;
}
l->Display();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
vec.push_back(4);
vec.push_back(5);
int size = vec.size();
cout << "This vector includes " << size << " elements:" << endl;
for(int i=0; i<size; i++) cout << vec[i] << "\t";
cout << endl;
return 0;
}
#include <vector>
using namespace std;
int main()
{
vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
vec.push_back(4);
vec.push_back(5);
int size = vec.size();
cout << "This vector includes " << size << " elements:" << endl;
for(int i=0; i<size; i++) cout << vec[i] << "\t";
cout << endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询