-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector_intro.cpp
91 lines (74 loc) · 1.84 KB
/
vector_intro.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<int> v;
vector <int> :: iterator itr;
int choice,x;
x: printf("Enter choice:\n1. Insert\n2.Delete\n3.Size\n4.Display by index\n5.Display by iterator\n6.Clear\n7.Exit\n");
printf("Enter your choice:\t");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the value:\t");
int item;
scanf("%d",&item);
v.push_back(item);
printf("Displaying using iterator:\n");
for(itr=v.begin(); itr!=v.end();itr++)
{
printf("%d\t", *itr);
}
printf("\n");
goto x;
break;
case 2:
printf("Deleting the last element.\n");
v.pop_back();
printf("Displaying using iterator:\n");
for(itr=v.begin(); itr!=v.end();itr++)
{
printf("%d\t", *itr);
}
printf("\n");goto x;
break;
case 3:
printf("Size of the vector: %d\n",v.size());
goto x;
break;
case 4:
printf("Displaying using index:\n");
for(int i=0; i<v.size();i++)
printf("%d\t",v[i]);
printf("\n");
goto x;
break;
case 5:
printf("Displaying using iterator:\n");
for(itr=v.begin(); itr!=v.end();itr++)
{
printf("%d\t", *itr);
}
printf("\n");
goto x;
break;
case 6:
v.clear();
printf("Displaying using iterator:\n");
for(itr=v.begin(); itr!=v.end();itr++)
{
printf("%d\t", *itr);
}
printf("\n");
goto x;
break;
case 7:
exit(1);
break;
default:
printf("Wrong choice!\n");
goto x;
}
return 0;
}