#include <iostream>
using namespace std;
const int m=3;
const int N = 3;
void funcvvod(int *p[N], int &last,int &k,int &l,int &j,int &n,int &high){
int kk;
cout << "Введите количество элементов " << endl;
cin >> kk;
if (k+kk > N*m){
cout << "Массив переполнен. Максимальное количество элементов = " << N*m << ". Введите меньшее количество элементов" << endl;
goto point;
}
k += kk;
if (p[0] == NULL){
p[0] = new int[m];
n = 0;
j = 0;
}
for (; l < k; l++, j++){
if (j == m){
j = 0;
n++;
p[n] = new int[m];
}
cin >> p[n][j];
last = j;
}
high = n + 1;
point:;
}
void funcvivod(int *p[N], int &first, int &last, int &high,int &n,int &l,int &k){
if (p[0] == NULL){
cout << "Элементов в очереди нет" << endl;
goto point;
}
cout << p[0][first] << endl;
first++;
k--;
if (first == m){
p[high] = NULL;
for (int i = 0; p[i] != NULL; i++)
p[i] = p[i + 1];
//delete p[high];
n--;
high--;
first = 0;
l = l - m;
}
if (p[1] == NULL){
if (first == last+1) {
p[0] = NULL;
l = 0;
first = 0;
high--;
}
}
point:;
}
void funclink(int *p[N], int &first, int &last, int &high){
int n = 0;
if (high == 0)
goto point;
for (int f = first; n < N; f++){ //n != high - 1 || f != last + 1
if (p[n] != NULL){
if ((f == first && n == 0 )|| (f == 0 && n != 0))
cout << "* ";
if (n == high - 1 && f == last + 1){
n++;
cout << endl;
continue;
}
if (f == m){
n++;
f = -1;
cout << endl;
continue;
}
cout << p[n][f] << " ";
}
else {
cout << "-" << endl;
n++;
}
}
cout << endl << "Первый: i=0, j=" << first << endl;
cout << "Последний: i=" << high - 1 << ", j=" << last << endl;
point:
if (high == 0){
for (int u = 0; u < N; u++){
cout << "-" << endl;
if (u == N - 1){
cout << "Первый: i=-1, j=-1" << endl;
cout << "Последний: i=-1" << ", j=-1" << endl;
}
}
}
}
int main() {
setlocale(LC_ALL, "Russian");
int n = 0;
int j = 0;
int high=0;
int first = 0, last=0, k = 0, l = 0;
int choose;
int **p = new int*[N];
for (int i = 0; i < N; i++)
p[i] = NULL;
//p[n] = new int[m];
label:
cout << "1. Ввести числа в очередь" << endl;
cout << "2. Вывести число из очереди" << endl;
cout << "3. Показать очередь" << endl;
cout << "0. Закончить работу" << endl;
cin >> choose;
switch (choose)
{
case 1:
funcvvod(p,last,k,l,j,n,high);
goto label;
case 2:
funcvivod(p,first,last,high,n,l,k);
goto label;
case 3:
cout << endl;
funclink(p,first,last,high);
goto label;
case 4:
goto labelend;
}
labelend:
delete[]p;
}