Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define N 10
- struct Deque {
- int data[N];
- int last;
- };
- typedef struct Deque Deque;
- void Creation(Deque *D);
- void AddL(Deque *D);
- void AddR(Deque *D);
- void DeleteL(Deque *D);
- void DeleteR(Deque *D);
- int OutputL(Deque *D);
- int OutputR(Deque *D);
- int Size(Deque *D);
- int main() {
- Deque d;
- int a=1;
- Creation(&d);
- while (a==1) {
- cout << "adding to the beginning: " << endl;
- AddL(&d);
- cout << "Add more? 1(yes)/2(no)" << endl;
- cin >> a;
- }
- a=1;
- while (a==1) {
- cout << "adding to the end: " << endl;
- AddR(&d);
- cout << "Add more? 1(yes)/2(no)" << endl;
- cin >> a;
- }
- cout << "output of the first element: " << endl;
- a = OutputL(&d);
- cout << a << endl;
- cout << "output of the last element: " << endl;
- a = OutputR(&d);
- cout << a << endl;
- cout << "deleting the first element: " << endl;
- DeleteL(&d);
- cout << "output of the first element: " << endl;
- a = OutputL(&d);
- cout << a << endl;
- cout << "deleting the last element: " << endl;
- DeleteR(&d);
- cout << "output of the last element: " << endl;
- a = OutputR(&d);
- cout << a << endl;
- int s=Size(&d);
- cout << "the size of the deck: " << s << endl;
- }
- void Creation(Deque *D) {
- D->last=0; }
- bool Full(Deque *D) {
- if (D->last==0)
- return true;
- else return false;
- }
- void AddL(Deque *D) { //добавление в начало
- if (D->last==N)
- cout<<"\nДек заполнен\n\n"; return;
- int value;
- cout<<"\nЗначение > ";
- cin>>value;
- for (int i=D->last; i>0; i--)
- D->data[i]=D->data[i-1];
- D->data[0]=value;
- D->last++;
- cout<<endl<<"Элемент добавлен\n\n";
- }
- void AddR(Deque *D) {//добавление элемента в конец
- if (D->last==N) {
- cout<<"\nДек заполнен\n\n"; return; }
- int value;
- cout<<"\nЗначение > "; cin>>value;
- D->data[D->last++]=value;
- cout<<endl<<"Элемент добавлен\n\n";
- }
- void DeleteL(Deque *D) {//удаление первого элемента
- for (int i=0; i<D->last; i++)
- D->data[i]=D->data[i+1]; D->last--;
- }
- void DeleteR(Deque *D) {//удаление последнего элемента
- D->last--;
- }
- int OutputL(Deque *D) {//вывод первого элемента
- return D->data[0];
- }
- int OutputR(Deque *D) {//вывод последнего элемента
- return D->data[D->last-1];
- }
- int Size(Deque *D) {//размер дека
- return D->last;
- }
Add Comment
Please, Sign In to add comment