Программы на C++. Форум разработчиков
Гость
У меня возникла ошибка: «Джордж» не называет тип в первой строке текстового файла. Мой профессор не отвечает, и я не уве
Сообщение
Гость » 19 мар 2024, 05:13
заголовок стека, включающий реализацию
Код: Выделить всё
#ifndef STACK_H
#define STACK_H
#include
template
class Stack {
private:
struct Node {
T data;
Node* next;
Node(const T& value) : data(value), next(nullptr) {}
};
Node* topPtr;
public:
Stack() : topPtr(nullptr) {}
~Stack() {
makeEmpty();
}
void push(const T& value) {
Node* newNode = new Node(value);
if (isEmpty()) {
topPtr = newNode;
} else {
newNode->next = topPtr;
topPtr = newNode;
}
}
T pop() {
if (isEmpty()) {
// Handle error when stack is empty
} else {
T poppedValue = topPtr->data;
Node* temp = topPtr;
topPtr = topPtr->next;
delete temp;
return poppedValue;
}
}
T peek() const {
if (isEmpty()) {
// Handle error when stack is empty
} else {
return topPtr->data;
}
}
bool isEmpty() const {
return topPtr == nullptr;
}
void makeEmpty() {
while (!isEmpty()) {
pop();
}
}
void print() const {
Node* current = topPtr;
while (current != nullptr) {
std::cout data next;
}
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78183914/im-having-an-error-that-george-does-not-name-a-type-on-line-one-of-txt-file-m[/url]
1710814399
Гость
заголовок стека, включающий реализацию [code]#ifndef STACK_H #define STACK_H #include template class Stack { private: struct Node { T data; Node* next; Node(const T& value) : data(value), next(nullptr) {} }; Node* topPtr; public: Stack() : topPtr(nullptr) {} ~Stack() { makeEmpty(); } void push(const T& value) { Node* newNode = new Node(value); if (isEmpty()) { topPtr = newNode; } else { newNode->next = topPtr; topPtr = newNode; } } T pop() { if (isEmpty()) { // Handle error when stack is empty } else { T poppedValue = topPtr->data; Node* temp = topPtr; topPtr = topPtr->next; delete temp; return poppedValue; } } T peek() const { if (isEmpty()) { // Handle error when stack is empty } else { return topPtr->data; } } bool isEmpty() const { return topPtr == nullptr; } void makeEmpty() { while (!isEmpty()) { pop(); } } void print() const { Node* current = topPtr; while (current != nullptr) { std::cout data next; } std::cout Подробнее здесь: [url]https://stackoverflow.com/questions/78183914/im-having-an-error-that-george-does-not-name-a-type-on-line-one-of-txt-file-m[/url]
0 Ответы
5 Просмотры
Последнее сообщение Anonymous
15 янв 2025, 05:58
0 Ответы
19 Просмотры
Последнее сообщение Anonymous
28 янв 2025, 21:45
0 Ответы
22 Просмотры
Последнее сообщение Anonymous
06 дек 2024, 00:37
0 Ответы
62 Просмотры
Последнее сообщение Anonymous
13 май 2024, 17:48
«ошибка: «T» не называет тип» при реализации связанного списка
Anonymous »
21 июн 2024, 21:24 » в форуме
C++
#include
#pragma once
class ListElement
{
public:
ListElement(T* d)
{
next = NULL;
data = d;
}
T* getData(void) {return data;}
void setNext(ListElement* n) {next = n;}
ListElement* getNext(void) {return next;}
private:
T* data;
ListElement*...
0 Ответы
16 Просмотры
Последнее сообщение Anonymous
21 июн 2024, 21:24