Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 12.06.2014, 20:59   #1
Валера1984
Пользователь
 
Регистрация: 10.02.2014
Сообщений: 14
По умолчанию Найти ошибку С++

Программа должна используя Дерево выводить список игроков сначала всех играющих в основном составе ниже играющих в резерве.... она же выводит всех в перемешку.... Почему?
Код:
#include"stdafx.h"
#include"iostream"
#include"conio.h"
#include <string.h>
 
using namespace std;
 
struct Data         
    {
        unsigned day;       
        unsigned month;     
        unsigned year;
    };
 
struct T_sport
    {
        char fio[40];
        Data d_birth;
        unsigned v_CSKA ;
        char MestoVkomande[20] ;
        char Sostav [20];
        
}; 
 
struct TreeNode
{
    //char MestoVkomande [20];
    string Sostav ;
    T_sport sport;
    TreeNode *next;
    TreeNode*child;
};
 
class osnovnoi
{
private:
    TreeNode *head;
public:
    osnovnoi()
    
    {
        head = new TreeNode;
        TreeNode *node1 = new TreeNode;
    //  node1->MestoVkomande="Forward";
        node1->Sostav="Main";
        node1->child = NULL;
        node1->next = NULL;
        head->child = node1;
        TreeNode *node2 = new TreeNode;
        //node2->MestoVkomande="Forward";   
        node2->Sostav="Reserve";
        node2->child = NULL;
        node2->next = NULL;
        node1->next = node2;
        //TreeNode *node3 = new TreeNode;
        //node3->MestoVkomande="Defender";  
        T_sport a = {"Ivanov I. I.",3,1,1984,2000,"Defender","Main"};
        TreeNode *nodeA = new TreeNode;
        nodeA->sport = a;
        nodeA->child = NULL;
        nodeA->next = NULL;
        node1->child = nodeA;
        TreeNode *nodeB = new TreeNode;
        T_sport b ={"Petrov A.A.",8,12,1987,2002, "Forward","Reserved"};
        nodeB->sport = b;
        nodeB->child = NULL;
        nodeB->next = NULL;
        node2->child = nodeB;
}
 
    void add_node()
    {
        T_sport a; 
    char c;
    cout<<endl<<"Enter data person\n";
    cout<<" fio ";
    cin.getline(a.fio,40);
    cout<<endl<<"Enter date of birthday: \n";
    cout<<" day (1-31) ";
    cin>>a.d_birth.day;
    cin.get(c);
    cout<<" month (1-12)";
    cin>>a.d_birth.month;
    cin.get(c);
    cout<<" year ";
    cin>>a.d_birth.year;
    cin.get(c);
    cout<<" v_CSKA ";
    cin>>a.v_CSKA;
    cin.get(c);
    cout<<" MestoVkomande ";
    cin.getline(a.MestoVkomande,20);
    cout<<" Sostav ";
    cin.getline(a.Sostav,20);
 
    TreeNode*node= head->child;
    
    while(true)
        {
        if (strcmp(node->Sostav.c_str(),a.Sostav)==0)
                {
                    TreeNode*newNode= new TreeNode;
                    newNode->sport=a;
                    newNode->child=NULL;
                    if(node->child == NULL)
                    node->child = newNode;
                else    
                {
 
                TreeNode *elem = node->child;
                    while(elem->next != NULL)
                        elem = elem->next;
                    elem->next = newNode;
                }
                return;
            }
            if(node->next == NULL)
                break;
            node = node->next;
        }
    TreeNode *newNode = new TreeNode;
        //newNode->MestoVkomande = a.MestoVkomande;
        newNode->Sostav= a.Sostav;
        newNode->child = NULL;
        newNode->next = NULL;
        node->next = newNode;
        TreeNode *nodeA = new TreeNode;
        nodeA->sport = a;
        nodeA->child = NULL;
        nodeA->next = NULL;
        newNode->child = nodeA;
 
    }
 
    void print_tree()
    {
        printf("[\n ");
        TreeNode *node = head->child;
        while(node != NULL)
        {
            cout<<" --> "<< node->Sostav.c_str()<<endl;
            if(node->child != NULL)
            {
                TreeNode *child = node->child;
                while(child != NULL)
                {
                 printf("%20s ! %2d.%2d.%4d ! %4d ! %15s ! %15s\n",child->sport.fio,child->sport.d_birth.day,child->sport.d_birth.month,child->sport.d_birth.year,child->sport.v_CSKA,child->sport.MestoVkomande,child->sport.Sostav);
 
         child= child->next;
                
                }
                
            }
            node=node->next;    
 
         }
        printf("]\n");
    }
 
   
};
 
int main()
{
    
    
    osnovnoi f;
    for(int i = 2; i < 5; i++)
    {   
        f.add_node();
    };
    
    f.print_tree();
      _getch();
 
    return 0;
}
Валера1984 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Помогите найти ошибку - StrToFloat выдаёт ошибку EConvertError для ячеек StringGrid (Delphi) Artsiom Помощь студентам 10 18.12.2013 14:10
Найти ошибку в коде (Для данной целочисленной матрицы размером n*m найти матрицу из 0 и 1...) код на C camel5 Помощь студентам 1 26.11.2013 06:11
найти ошибку Славик__077 Общие вопросы C/C++ 0 31.01.2011 14:39
найти ошибку sergio11 Паскаль, Turbo Pascal, PascalABC.NET 2 19.05.2010 01:22
найти ошибку rUs_LAN Общие вопросы C/C++ 8 14.05.2009 12:02