Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Лабораторная работа 3 #61

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

George-Amberson
Copy link

@UsovaMA
@LebedevIlyaG
Лаборатоная работа по стеку и очереди

Copy link

@UsovaMA UsovaMA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поправить некоторые моменты нужно. Сразу дополнительное задание первое (в main): Расположить элементы целочисленного массива (int* massive = new int [size];) в обратном порядке с использованием стека библиотечного (#include ) и своего.


## Цели и задачи

В рамках лабораторной работы ставится задача создания программных средств, поддерживающих эффективное хранение матриц специального вида (верхнетреугольных) и выполнение основных операций над ними:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Описание от матриц осталось)

include/Stack.h Outdated
Comment on lines 10 to 16
Stack()
{
Array = 0;
size = 0;
first = 0;
last = 1;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Несовсем корректная инициализация. Если у тебя изначально пустой стек, то использовать для обозначения первого элемента 0 странно. Ты как бы говоришь, что нижний элемент в стеке имеет индекс 0, аналогично с last верхний элемент в пустом стеке у тебя имеет индекс 1. Если у тебя стек пуст, то эти значения нужно устанавливать в какое-то отличное от индексации число, например, -1.

include/Stack.h Outdated
Comment on lines 20 to 23
Array = new A1*[_size];
size = _size;
first = 0;
last = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично первому замечанию, если ты только создал стек и там лежит 0 элементов, то говорить, что first и last не могут иметь значение 0. Это бы означало, что у тебя стек с одним элементом.

include/Stack.h Outdated
}
bool IsFull()
{
return(last==size);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Размер стека 10. Индексация с 0 и last для верхнего 10-го элемента будет 9.

bool IsFull()
{
return(last==size);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще говоря, будет полезным добавить поле в класс DataCount, хранящее число элементов в стеке. Повысит читабельность кода и как раз убережёт от подобных ошибок

}
virtual A1& pop()
{
if (this->IsEmpty()) throw logic_error("Stack is empty");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично нужна проверка на NULL


using namespace std;
template<class A1>
class Stack
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай разнесём всё же объявление класса и реализацию методов. Сначала пусть идёт полное объявление, а потом уже реализации

include/Queue.h Outdated
Queue(Queue& lhs) :Stack<A2>(lhs){}
Queue(int _size) :Stack<A2>(_size){}
~Queue(){}
void push(A2& lhs)override
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А разве push для очереди и для стека не работают одинаково?)

#include "Stack.h"

template<class A2>
class Queue :public Stack<A2>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Замечания, написанные для стека, сохраняются и для очереди

include/Stack.h Outdated
{
return Array;
}
virtual void push(A1& lhs)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Неплохо бы добавить const для типа lhs, так как по смыслу мы не должны его менять, укладывая в стек

@George-Amberson
Copy link
Author

@UsovaMA
Все замечания учтены, доп задание выполнил

@George-Amberson
Copy link
Author

@UsovaMA
Дополнительное задание на поиск входит ли элемент в стек и в очередь и поиск минимума на стеке и на очереди сделал

@UsovaMA
Copy link

UsovaMA commented Oct 26, 2020

Молодец. Основная лабораторная принята, реализованные доп. задания также приняты.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants