内容有所粗糙,请见谅!
#include<iostream>
#include<stack>
#include<vector>
#define maxsize 100
using namespace std;
//栈的存储类型,结构体实现
//typedef struct stack{
// int data;
// int *top;
//}sqstack;
//
//void InitStack(sqstack&s)
//{
// *s.top = -1;
//}
//
//bool stackempty(sqstack&s)
//{
// if (*s.top == -1)
// return true;
// return false;
//}
//
//bool push(sqstack&s, int x)
//{
// if (*s.top == maxsize - 1)
// return false;
// s.data[++s.top] = x;
// return true;
//}
//
//bool pop(sqstack&s, int &y)
//{
// if (*s.top == -1)
// return false;
// y = s.data[s.top--];
// return true;
//}
//
//bool gettop(sqstack&s, int&z)
//{
// if (*s.top == -1)
// return false;
// z = s.data[s.top];
// return true;
//
//
//
//}
int main()
{ //STL实现
//vectord的初始化,添加,元素个数,是否为空 ,取元素,插入,删除,比较 清空,遍历
vector<int>vec1= {1,2,3,4,5,6,7,8,9};
vector<int>vec2(vec1);
vector<int>vec3(vec1.begin(), vec1.end());
vector<int>vec4(10); //10个0
vector<int>vec5(10, 4);
cout << "**********" << endl;
/*vec1.push_back(100);
cout << vec1.size() << endl;
cout << vec1.empty() << endl;
cout << vec1[4] << endl;*/
/*vec1.insert(vec1.begin()+2, 3, 5)*/;//(开始的位置,几个,所插入的数是什么)
vec1.erase(vec1.end()-1);
vec1.pop_back();
vec1.erase(vec1.begin()+1 , vec1.end()-1);
cout << "**********" << endl;
vector<int>vec6 = { 1,2,3,4,5,6,7,8,9 };
cout << (vec1 == vec2) ? true : false ;
cout << endl;
vector<int>::iterator iter = vec1.begin();
vec1.clear();
vector<int>::const_iterator iterator = vec1.begin();
for (; iterator != vec1.end(); iterator++)
{
cout << *iterator;
}
vector<int>ve6;
ve6.push_back(3);
ve6.push_back(2);
ve6.push_back(1);
ve6.push_back(0);
cout << "下标:" << ve6[3] << endl;
cout << "迭代器:" << endl;
ve6.insert(ve6.begin(), 789);
ve6.insert(ve6.end(), 456);
for (vector<int>::iterator i = ve6.begin(); iterator != ve6.end(); ++iterator)
{
cout << *iterator << endl;
}
vector<int>de(10);
for (int i = 0; i < 10;++i)
{
de[i] = i;
}
for (vector<int>::iterator i = de.begin(); iterator != de.end(); ++iterator)
{
cout << *iterator << endl;
}
/*cout << v1.front() << endl;
cout << v1.back() << endl;*/
system("pause");
return 0;
}