Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.75/4: Рейтинг темы: голосов - 4, средняя оценка - 4.75
0 / 0 / 1
Регистрация: 11.09.2015
Сообщений: 83
1

Сделать пользовательский класс QueueWithPriority шаблонным классом

08.11.2016, 00:50. Показов 787. Ответов 14
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
программа работает с определенным типом данных, сказали сделать чтобы можно было работать с любым, а я не совсем понимаю как расставить правильно шаблоны
C++
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
typedef enum
{
    LOW,
    NORMAL,
    HIGH } ElementPriority;
 
/** QueueElement structure */
struct QueueElement
{
    /// Priority enum #ElementPriority
    ElementPriority priority;
    /// Element name
    ///  template <class T> 
    std::string name;
    /** Default constructor */
    QueueElement(std::string nm, ElementPriority prt);
    /** Alternate constructor */
    //QueueElement(char nm[], ElementPriority prt);
   // Overload < for sort. Desperated. */
   // friend bool operator<(const QueueElement &leftel, const QueueElement &rightel);
   // Overload << for iostream
   // friend std::ostream& operator<<( std::ostream &ostr, const QueueElement &L );
 
};
 
/// Container type for #QueueWithPriority
typedef std::list<QueueElement> cont;
/// Container iterator type for #QueueWithPriority
typedef cont::iterator It;
/// Container reverse iterator type for #QueueWithPriority
typedef cont::reverse_iterator rIt;
 
/** QueueWithPriority container for QueueElement */
///template <class T>
class QueueWithPriority
{
private:
    cont list;
public:
    /// Constructor
    QueueWithPriority(void);
    /// Desctructor
    ~QueueWithPriority(void);
    /// put #QueueElement
    void putElement(const QueueElement &element);
    /// put char name[] and #ElementPriority priority
    void putElement(const char nm[], ElementPriority prt);
    /// return first #QueueElement
    QueueElement getElement(void);
    /// accelerate - set all #QueueElement priority to HIGH and move afrer HIGH elements and before  NORMAL elements
    void accelerate(void);
    /// return #__queue size
    int size(void){
        return list.size();
    }
    /// for human print #QueueWithPriority
    void print_queue(void);
 
};
 
QueueElement::QueueElement(std::string nm, ElementPriority prt)
{
    name=nm;
    priority=prt;
}
 
/*QueueElement::QueueElement(char nm[], ElementPriority prt)
{
    name = std::string(nm),
    priority = prt;
}*/
 
bool operator<(const QueueElement &leftel, const QueueElement &rightel)
{
    return (leftel.priority < rightel.priority);
}
 
std::ostream& operator<<( std::ostream &ostr, const QueueElement &L )
{
    char *priority_name;
    switch (L.priority)
    {
    case LOW: priority_name = "LOW";
        break;
    case NORMAL: priority_name = "NORMAL";
        break;
    case HIGH: priority_name = "HIGH";
        break;
    default: priority_name = "None";
    }
 
    ostr << "Q("<< L.name << "," << priority_name << ")";
    return ostr;
}
 
/// Constructor
QueueWithPriority::QueueWithPriority()
{
 
}
/// Destructor
QueueWithPriority::~QueueWithPriority()
{
 
}
 
void QueueWithPriority::putElement(const QueueElement &element)
{
    It iter;
    int check;
    bool insert = false;
    if ((!list.empty()) & (element.priority != LOW))
    {
        for(iter=list.begin(); iter != list.end(); iter++)
        {
            check = iter->priority - element.priority;
            if (check == -1)
            {
                list.insert(iter, element);
                insert = true;
                break;
            }
        }
        if (!insert)
        {
            list.push_front(element);
        }
    } else {
        list.push_back(element);
    }
}
 
void QueueWithPriority::putElement(const char name[], ElementPriority priority)
{
    putElement(QueueElement(name, priority));
}
 
QueueElement QueueWithPriority::getElement()
{
    if (!list.empty())
    {
        QueueElement qe = list.front();
        list.pop_front();
        return qe;
    } else {
        std::cerr << "No more QueueElement in QueueWithPriority!"<< std::endl;
    }
 
}
 
void QueueWithPriority::accelerate()
{
    It iter1;
    It iter2;
    bool low = false;
 
    for(iter1=--list.end();; iter1--)
    {
        if (iter1->priority == LOW)
        {
            iter1->priority = HIGH;
            iter2 = iter1;
            low = true;
        }
        if ( iter1 == list.begin())
        {
            break;
        }
    }// END for
 
    if (low)
    {
        for (iter1 = list.begin(); iter1 != list.end(); iter1++)
        {
            if (iter1->priority == NORMAL)
            {
                list.splice(iter1, list, iter2, list.end());
                break;
            }// END IF
        }
    }// END IF is_low
} // END accelerate
 
void QueueWithPriority::print_queue()
{
    It iter;
    std::cout << "[";
    for(iter=list.begin(); iter != list.end();iter++)
    {
        std::cout<< *iter<< ",";
    }
    std::cout << "]" << std::endl;
}
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
08.11.2016, 00:50
Ответы с готовыми решениями:

Сделать класс «Числовой вектор» шаблонным классом. Построить пример для вектора типа Integer
Здравствуйте, помогите пожалуйста, код ругается на &quot;error C2679: бинарный &quot;&gt;&gt;&quot;: не найден оператор,...

Не работает typedef с шаблонным классом
доброго времени суток форумчане есть функция с консольной менюшкой, в нее приходит аргумент,...

Работа с шаблонным классом valarray
Доброго времени суток, господа! для шаблонного класса valarray есть конструктор создания массива...

Не могу воспользоватсья шаблонным классом
Не могу воспользоваться шаблонным классом, не понимаю, что не верно в коде #include &quot;iostream&quot;...

14
7793 / 6560 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
08.11.2016, 07:37 2
C++
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
template <class T>
class QueueWithPriority
{
private:
    std::list<T> list;
public:
    /// Constructor
    QueueWithPriority(void);
    /// Desctructor
    ~QueueWithPriority(void);
    /// put #QueueElement
    void putElement(const T &element);
    /// put char name[] and #ElementPriority priority
    void putElement(const char nm[], ElementPriority prt);
    /// return first #QueueElement
    T getElement(void);
    /// accelerate - set all #QueueElement priority to HIGH and move afrer HIGH elements and before  NORMAL elements
    void accelerate(void);
    /// return #__queue size
    int size(void){
        return list.size();
    }
    /// for human print #QueueWithPriority
    void print_queue(void);
};
0
0 / 0 / 1
Регистрация: 11.09.2015
Сообщений: 83
08.11.2016, 08:36  [ТС] 3
nmcf, если следовать вашему варианту то struct QueueElement полностью пропадает

Добавлено через 1 минуту
а как сделать шаблон в самой структуре QueueElement я пытался, но появлялись проблемы со списком
0
7793 / 6560 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
08.11.2016, 09:26 4
C++
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
template <class T>
struct QueueElement
{
    ElementPriority priority;
    T name;
    QueueElement(T nm, ElementPriority prt);
};
 
template <class T>
QueueElement<T>::QueueElement(T nm, ElementPriority prt): name(nm), priority(prt) {}
 
template <class T>
class QueueWithPriority
{
private:
    std::list<T> list;
public:
    /// Constructor
    QueueWithPriority(void);
    /// Desctructor
    ~QueueWithPriority(void);
    /// put #QueueElement
    void putElement(const T &element);
    /// put char name[] and #ElementPriority priority
    void putElement(const char nm[], ElementPriority prt);
    /// return first #QueueElement
    T getElement(void);
    /// accelerate - set all #QueueElement priority to HIGH and move afrer HIGH elements and before  NORMAL elements
    void accelerate(void);
    /// return #__queue size
    int size(void){
        return list.size();
    }
    /// for human print #QueueWithPriority
    void print_queue(void);
};
 
//...
 
QueueWithPriority<QueueElement<std::string>> q;
0
0 / 0 / 1
Регистрация: 11.09.2015
Сообщений: 83
09.11.2016, 19:47  [ТС] 5
nmcf, а можете подсказать, если я ставлю
C++
1
template <typename t>
перед функцией которая вызывается из
C++
1
main()
появляется ошибка "no matching function for call to...", что делать в этом случае?
0
7793 / 6560 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
09.11.2016, 20:12 6
Как это выглядит?
0
0 / 0 / 1
Регистрация: 11.09.2015
Сообщений: 83
09.11.2016, 20:14  [ТС] 7
C++
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include <iostream>
#include <list>
#include <iterator>
#include <string>
 
typedef enum
{
  LOW,
  NORMAL,
  HIGH
} ElementPriority;
 
template <typename t>
struct QueueElement
{
  ElementPriority priority;
  t name;
  QueueElement(t nm, ElementPriority prt);
};
 
/*typedef std::list<QueueElement> cont;
typedef cont::iterator It;
typedef cont::reverse_iterator rIt;
*/
 
template <typename t>
class QueueWithPriority
{
private:
  std::list<t> list;
public:
  QueueWithPriority(void);
  ~QueueWithPriority(void);
  void putElement(const QueueElement<t> &element);
  QueueElement<t> getElement(void);
  void accelerate(void);
  void printQueue(void);
  int size(void)
  {
    return list.size();
  }
};
 
template <typename t>
QueueElement<t>::QueueElement(t nm, ElementPriority prt)
 
{
  name=nm;
  priority=prt;
}
template <typename t>
bool operator<(const QueueElement<t> &leftel, const QueueElement<t> &rightel)
{
  return (leftel.priority < rightel.priority);
}
 
template <typename t>
std::ostream& operator<<( std::ostream &ostr, const QueueElement<t> &P )
{
  const char *priority_name;
  switch (P.priority)
    {
    case LOW: priority_name = "LOW";
      break;
    case NORMAL: priority_name = "NORMAL";
      break;
    case HIGH: priority_name = "HIGH";
      break;
    default: priority_name = "None";
    }
  ostr << "[" << P.name << "," << priority_name << "]";
  return ostr;
}
 
template <typename t>
QueueWithPriority<t>::QueueWithPriority()
{
 
}
 
template <typename t>
QueueWithPriority<t>::~QueueWithPriority()
{
 
}
 
template <typename t>
void QueueWithPriority<t>::putElement(const QueueElement<t> &element)
{
  typename std::list<t>::iterator iter;
  int check;
  bool insert = false;
  if ((!list.empty()) & (element.priority != LOW))
    {
      for(iter=list.begin(); iter != list.end(); iter++)
        {
          check = iter->priority - element.priority;
          if (check == -1)
            {
              list.insert(iter, element);
              insert = true;
              break;
            }
        }
      if (!insert)
        {
          list.push_front(element);
        }
    } else {
      list.push_back(element);
    }
}
 
template <typename t>
QueueElement<t> QueueWithPriority<t>::getElement()
{
  if (!list.empty())
    {
      QueueElement<t> qe = list.front();
      list.pop_front();
      return qe;
    }
  else
    {
      std::cerr << "EMPTY"<< std::endl;
      exit(2);
    }
}
 
 
template <typename t>
void QueueWithPriority<t>::accelerate()
{
    typename std::list<t>::iterator iter1;
    typename std::list<t>::iterator iter2;
    /*list::iterator iter1;
    list::iterator iter2;*/
    bool is_low = false;
    for(iter1=--list.end();; iter1--)
    {
        if (iter1->priority == LOW)
        {
            iter1->priority = HIGH;
            iter2 = iter1;
            is_low = true;
        }
        if ( iter1 == list.begin())
        {
            break;
        }
    }
    if (is_low)
    {
        for (iter1 = list.begin(); iter1 != list.end(); iter1++)
        {
            if (iter1->priority == NORMAL)
            {
                list.splice(iter1, list, iter2, list.end());
                break;
            }
        }
    }
}
 
template <typename t>
void QueueWithPriority<t>::printQueue()
{
  typename std::list<t>::iterator iter;
  for(iter=list.begin(); iter != list.end();iter++)
    {
      std::cout<< *iter<< " ";
    }
  std::cout  << std::endl;
}
void printList(std::list<int> l)
{
  std::list<int>::iterator iter;
  for (iter=l.begin(); iter != l.end(); ++iter)
    {
      std::cout << *iter << " ";
    }
  std::cout << '\n';
}
 
void printListForm(std::list<int> l)
{
  std::list<int>::iterator iter1 = l.begin();
  std::list<int>::reverse_iterator iter2  = l.rbegin();
  for (size_t i = 0; i != l.size()/2; ++i, ++iter1, ++iter2)
    {
      std::cout << *iter1 << ' ';
      std::cout << *iter2 << ' ';
    }
  std::cout << '\n';
}
 
void input(std::list<int> &l)
{
  int tmp = 0;
  while(std::cin >> tmp)
    {
      try
      {
        if (tmp > 20 || tmp < 0)
          {
            throw 1;
          }
      }
      catch(int i)
      {
        std::cerr << "!!error input!!\n";
        exit(i);
      }
      l.push_back(tmp);
    }
}
 
template <class t> //???
void head(const int argc, const char *argv[])
{
  if (argc >= 1)
    {
      QueueWithPriority<t> queue;
      switch (argv[1][0])
        {
        case '1':
          {
            while(!std::cin.eof())
              {
                std::string command;
                std::cin >> command;
                if(command == "add")
                  {
                    std::string tmp1;
                    std::string tmp2;
                    ElementPriority priority;
                    std::cin >> tmp1;
                    std::cin >> tmp2;
                    if(tmp1 == "low")
                      {
                        priority = LOW;
                      }
                    if(tmp1 == "normal")
                      {
                        priority = NORMAL;
                      }
                    if(tmp1 == "high")
                      {
                        priority = HIGH;
                      }
                    if((tmp1 !=  "low") && (tmp1 != "normal") && (tmp1 != "high"))
                      {
                        std::cout << "INVALID COMMAND\n";
                        continue;
                      }
                    queue.putElement(QueueElement<t>(tmp2, priority));
                  }
                if (command == "get")
                  {
                    std::cout << queue.getElement() << std::endl;
                  }
                if (command == "accelerate")
                  {
                    queue.accelerate();
                  }
                if ((command != "accelerate") && (command != "get") && (command != "add"))
                  {
                    std::cerr << "INVALID COMMAND\n";
                    continue;
                  }
              }
          }
        case '2':
          {
            std::list<int> list;
            input(list);
            printList(list);
            std::cout << std::endl;
            printListForm(list);
          }
        }
    }
  else
    {
      std::cout << "!!invalid arguments!!!";
    }
}
 
 
int main (int argc, const char* argv[])
{
  head(argc, argv); //тут ошибка
  return 0;
}
Добавлено через 22 секунды
в низу кода отмеченно
0
7793 / 6560 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
09.11.2016, 20:59 8
А зачем ты к head прикрутил template? В каком месте у тебя определяется тип элемента очереди?
0
0 / 0 / 1
Регистрация: 11.09.2015
Сообщений: 83
09.11.2016, 21:18  [ТС] 9
nmcf, в head используется
C++
1
QueueWithPriority<t> queue;
и
C++
1
QueueElement<t>(tmp2, priority)
Добавлено через 14 минут
а тип очереди определяется при вводе с консоли или из файла
0
7793 / 6560 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
09.11.2016, 21:20 10
Это понятно. Где по логике программы определяется тип? Где-то он должен быть указан явно, чтобы шаблон заработал. Если в этой функции, то вместо t подставляй тип.

Добавлено через 50 секунд
Цитата Сообщение от Dassis Посмотреть сообщение
тип очереди определяется при вводе с консоли или из файла
Так не будет работать, тип должен быть определён явно на этапе компиляции.
0
0 / 0 / 1
Регистрация: 11.09.2015
Сообщений: 83
09.11.2016, 22:55  [ТС] 11
ставлю std::string вылетают итераторы
0
7793 / 6560 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
09.11.2016, 23:29 12
Актуальный вариант покажи.
0
0 / 0 / 1
Регистрация: 11.09.2015
Сообщений: 83
09.11.2016, 23:41  [ТС] 13
C++
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#include <iostream>
#include <list>
#include <iterator>
#include <string>
 
typedef enum
{
  LOW,
  NORMAL,
  HIGH
} ElementPriority;
 
struct QueueElement
{
  ElementPriority priority;
  std::string name;
  QueueElement(std::string nm, ElementPriority prt);
};
 
typedef std::list<QueueElement> cont;
typedef cont::iterator It;
typedef cont::reverse_iterator rIt;
 
 
class QueueWithPriority
{
private:
  cont list;
public:
  QueueWithPriority(void);
  ~QueueWithPriority(void);
  void putElement(const QueueElement &element);
  QueueElement getElement(void);
  void accelerate(void);
  void printQueue(void);
  int size(void)
  {
    return list.size();
  }
};
 
QueueElement::QueueElement(std::string nm, ElementPriority prt)
 
{
  name=nm;
  priority=prt;
}
 
 
bool operator<(const QueueElement &leftel, const QueueElement &rightel)
{
  return (leftel.priority < rightel.priority);
}
 
std::ostream& operator<<( std::ostream &ostr, const QueueElement &P )
{
  const char *priority_name;
  switch (P.priority)
    {
    case LOW: priority_name = "LOW";
      break;
    case NORMAL: priority_name = "NORMAL";
      break;
    case HIGH: priority_name = "HIGH";
      break;
    default: priority_name = "None";
    }
  ostr << "[" << P.name << "," << priority_name << "]";
  return ostr;
}
 
QueueWithPriority::QueueWithPriority()
{
 
}
 
QueueWithPriority::~QueueWithPriority()
{
 
}
 
void QueueWithPriority::putElement(const QueueElement &element)
{
  It iter;
  int check;
  bool insert = false;
  if ((!list.empty()) & (element.priority != LOW))
    {
      for(iter=list.begin(); iter != list.end(); iter++)
        {
          check = iter->priority - element.priority;
          if (check == -1)
            {
              list.insert(iter, element);
              insert = true;
              break;
            }
        }
      if (!insert)
        {
          list.push_front(element);
        }
    } else {
      list.push_back(element);
    }
}
 
QueueElement QueueWithPriority::getElement()
{
  if (!list.empty())
    {
      QueueElement qe = list.front();
      list.pop_front();
      return qe;
    }
  else
    {
      std::cerr << "EMPTY"<< std::endl;
      exit(2);
    }
}
 
void QueueWithPriority::accelerate()
{
    It iter1;
    It iter2;
    bool is_low = false;
    for(iter1=--list.end();; iter1--)
    {
        if (iter1->priority == LOW)
        {
            iter1->priority = HIGH;
            iter2 = iter1;
            is_low = true;
        }
        if ( iter1 == list.begin())
        {
            break;
        }
    }
    if (is_low)
    {
        for (iter1 = list.begin(); iter1 != list.end(); iter1++)
        {
            if (iter1->priority == NORMAL)
            {
                list.splice(iter1, list, iter2, list.end());
                break;
            }
        }
    }
}
 
void QueueWithPriority::printQueue()
{
  It iter;
  for(iter=list.begin(); iter != list.end();iter++)
    {
      std::cout<< *iter<< " ";
    }
  std::cout  << std::endl;
}
void printList(std::list<int> l)
{
  std::list<int>::iterator iter;
  for (iter=l.begin(); iter != l.end(); ++iter)
    {
      std::cout << *iter << " ";
    }
  std::cout << '\n';
}
 
void printListForm(std::list<int> l)
{
  std::list<int>::iterator iter1 = l.begin();
  std::list<int>::reverse_iterator iter2  = l.rbegin();
  for (size_t i = 0; i != l.size()/2; ++i, ++iter1, ++iter2)
    {
      std::cout << *iter1 << ' ';
      std::cout << *iter2 << ' ';
    }
  std::cout << '\n';
}
 
void input(std::list<int> &l)
{
  int tmp = 0;
  while(std::cin >> tmp)
    {
      try
      {
        if (tmp > 20 || tmp < 0)
          {
            throw 1;
          }
      }
      catch(int i)
      {
        std::cerr << "!!error input!!\n";
        exit(i);
      }
      l.push_back(tmp);
    }
}
 
void head(const int argc, const char* argv[])
{
  if (argc >= 1)
    {
      QueueWithPriority queue;
      switch (argv[1][0])
        {
        case '1':
          {
            while(!std::cin.eof())
              {
                std::string command;
                std::cin >> command;
                if(command == "add")
                  {
                    std::string tmp1;
                    std::string tmp2;
                    ElementPriority priority;
                    std::cin >> tmp1;
                    std::cin >> tmp2;
                    if(tmp1 == "low")
                      {
                        priority = LOW;
                      }
                    if(tmp1 == "normal")
                      {
                        priority = NORMAL;
                      }
                    if(tmp1 == "high")
                      {
                        priority = HIGH;
                      }
                    if((tmp1 !=  "low") && (tmp1 != "normal") && (tmp1 != "high"))
                      {
                        std::cout << "INVALID COMMAND\n";
                        continue;
                      }
                    queue.putElement(QueueElement(tmp2, priority));
                  }
                if (command == "get")
                  {
                    std::cout << queue.getElement() << std::endl;
                  }
                if (command == "accelerate")
                  {
                    queue.accelerate();
                  }
                if ((command != "accelerate") && (command != "get") && (command != "add"))
                  {
                    std::cerr << "INVALID COMMAND\n";
                    continue;
                  }
              }
          }
        case '2':
          {
            std::list<int> list;
            input(list);
            printList(list);
            std::cout << std::endl;
            printListForm(list);
          }
        }
    }
  else
    {
      std::cout << "!!invalid arguments!!!";
    }
}
 
int main (const int argc, const char* argv[])
{
  head(argc, argv);
}
Добавлено через 3 минуты
nmcf,
C++
1
2
3
typedef std::list<QueueElement> cont;
typedef cont::iterator It;
typedef cont::reverse_iterator rIt;
, на мой взгляд перестаёт работать из-за этого, а как совмещать
C++
1
typedef
и
C++
1
template
я не знаю
0
7793 / 6560 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
10.11.2016, 00:01 14
Ну не используй typedef. Запиши развёрнуто.
1
0 / 0 / 1
Регистрация: 11.09.2015
Сообщений: 83
10.11.2016, 00:03  [ТС] 15
nmcf, как?
0
10.11.2016, 00:03
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
10.11.2016, 00:03
Помогаю со студенческими работами здесь

Не могу разобраться с шаблонным классом
Привет. Не могу разобраться в нижеизложенной ситуации. Вопрос: почему такая конструкция не...

Шаблонная функция с параметром - шаблонным классом
Интересный вещи происходят... template &lt;class T&gt; struct S { typedef T *Pointer; };...

Меню для работы с шаблонным классом
Здравствуйте, уважаемые программисты. Пожалуйста, помогите понять, что нужно делать. В задании...

.EXE и .DLL (ошибка LNK2019 с шаблонным классом)
У меня есть два проекта - первый это dll-проект, и второй это exe-проект. Мне нужно использовать...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
15
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru