powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / C++ [игнор отключен] [закрыт для гостей] / Нужна помощь!!!
5 сообщений из 5, страница 1 из 1
Нужна помощь!!!
    #34194077
XiPoMaHt
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Что такое двунаправленная очередь?
НУжно решить следующую проблемку : Создать шаблон класса,реализующий двунаправленную очередь.Для предоставления элемента очереди использовать шаблон класса Node.Определить функции добавления элемента и вывод ее содержимого.
На толкните на мысль....
...
Рейтинг: 0 / 0
Нужна помощь!!!
    #34194093
kolobok0
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
XiPoMaHtЧто такое двунаправленная очередь?
НУжно решить следующую проблемку : Создать шаблон класса,реализующий двунаправленную очередь.Для предоставления элемента очереди использовать шаблон класса Node.Определить функции добавления элемента и вывод ее содержимого.
На толкните на мысль....

это значит что каждый элемент очереди должен знать как следующий элемент, так и предыдущий...дабы обеспечить возможность прохода как вперёд так и взад...

(круглый)
...
Рейтинг: 0 / 0
Нужна помощь!!!
    #34194166
XiPoMaHt
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
КАк я понял - это таже очередь,только элемент очереди знает предшествующий и последующий за ним элементы.
Но тогда вопрос для чего двунаправленая очередь ,если нужно только реализовать функцию добавления и вывода на экран?
Код: plaintext
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.
struct Node
{
	int d;
	Node *p;
};
Node *first(int d);
void add(Node **pend,int d);
int del(Node **pbeg);
//-----
int main()
{
	Node *pbeg=first( 1 );
	Node *pend=pbeg;
	for (int i= 2 ;i< 6 ;i++) add(&pend,i);
	while (pbeg) cout<<del(&pbeg)<<' ';
	getch();
	return  0 ;
}
//-------
//Начальное оформление очереди
Node *first(int d)
{
	Node *pv=new Node;
	pv->d=d;
	pv->p= 0 ;
	return pv;
}
//--------
//добавление в конец
void add(Node **pend,int d)
{
	Node *pv=new Node;
	pv->d=d;
	pv->p= 0 ;
	(*pend)->p=pv;
	*pend=pv;
}
//--------
//выборка
int del (Node **pbeg)
{
	int temp=(*pbeg)->d;
	Node *pv=*pbeg;
	*pbeg=(*pbeg)->p;
	delete pv;
	return temp;
}
...
Рейтинг: 0 / 0
Нужна помощь!!!
    #34194177
Akh
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Используй что-нибудь типа _List_node_base, _List_node

Код: plaintext
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.
// List implementation -*- C++ -*-

// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Hewlett-Packard Company makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 *
 * Copyright (c) 1996,1997
 * Silicon Graphics Computer Systems, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Silicon Graphics makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 */

/** @file stl_list.h
 *  This is an internal header file, included by other library headers.
 *  You should not attempt to use it directly.
 */

#ifndef __GLIBCPP_INTERNAL_LIST_H
#define __GLIBCPP_INTERNAL_LIST_H

#include <bits/concept_check.h>

namespace std
{
  // Supporting structures are split into common and templated types; the
  // latter publicly inherits from the former in an effort to reduce code
  // duplication.  This results in some "needless" static_cast'ing later on,
  // but it's all safe downcasting.
  
  /// @if maint Common part of a node in the %list.  @endif
  struct _List_node_base
  {
    _List_node_base* _M_next;   ///< Self-explanatory
    _List_node_base* _M_prev;   ///< Self-explanatory
  };
  
  /// @if maint An actual node in the %list.  @endif
  template<typename _Tp>
    struct _List_node : public _List_node_base
  {
    _Tp _M_data;                ///< User's data.
  };
  
 //Далее я поскипал

...
Рейтинг: 0 / 0
Нужна помощь!!!
    #34194198
XiPoMaHt
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
спасиб
...
Рейтинг: 0 / 0
5 сообщений из 5, страница 1 из 1
Форумы / C++ [игнор отключен] [закрыт для гостей] / Нужна помощь!!!
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]