Форум: Форум C++Разное
Новые темы: 00
MySQL на примерах. Авторы: Кузнецов М.В., Симдянов И.В. PHP Puzzles. Авторы: Кузнецов М.В., Симдянов И.В. PHP. Практика создания Web-сайтов (второе издание). Авторы: Кузнецов М.В., Симдянов И.В. MySQL 5. В подлиннике. Авторы: Кузнецов М.В., Симдянов И.В. Программирование. Ступени успешной карьеры. Авторы: Кузнецов М.В., Симдянов И.В.
ВСЕ НАШИ КНИГИ
Консультационный центр SoftTime

Форум C++

Выбрать другой форум

 

Здравствуйте, Посетитель!

вид форума:
Линейный форум Структурный форум

тема: помогите срочно!!!!!!!!!!!!!!!!
 
 автор: wey111   (07.10.2010 в 10:09)   письмо автору
 
 

#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;


class List
{
public:
List(List& list);
List(int num);
~List();
void out_list();
void add_list(List& list);
void insert(int elem);
private:
struct node
{
int info;
struct node *next;
};
private:
node* m_head;
int count;
};

List::List(int num)
{
m_head=NULL;
for(int i=0;i<num;i++)
{
this->insert(rand()%100);
}
}

List::List(List& list)
{
m_head=NULL;
node* p1=list.m_head;
while(p1)
{
this->insert(p1->info);
p1=p1->next;
}
}

void List::insert(int elem)
{
node* p = m_head;
node* el = new node;
el->info = elem;
el->next = NULL;
if(!m_head)
{
m_head = el;
}else if(m_head->info>el->info)
{
el->next = m_head;
m_head = el;
}else
{
while(p->next)
{
if(p->info<=el->info && p->next->info>=el->info)
{
el->next = p->next;
p->next = el;
break;
}
p=p->next;
}
if(!p->next)
{
p->next = el;
}
}
}
List::~List()
{
node* p =m_head;
while(p)
{
node* temp = p;
p=p->next;
delete temp;
}
}
void List::out_list()
{
node* p = m_head;
if(p)
{
while(p)
{
cout<<p->info<<' ';
p=p->next;
};
}else
{
cout<<"empty list"<<endl;
}
cout<<endl;
}

void List::add_list(List& list)
{
node* p1=list.m_head;
while(p1)
{
this->insert(p1->info);
p1=p1->next;
}
}

void main()
{
srand((unsigned)time(NULL));

List list1(5);
cout<<"List1:"<<endl;
list1.out_list();

List list2(list1);
cout<<"List1:"<<endl;
list2.out_list();

List list3(6);
cout<<"List3:"<<endl;
list3.out_list();

list2.add_list(list3);
cout<<"List2+list3:"<<endl;
list2.out_list();

getch();
ПОМОГИТЕ ПОЖАЛУЙСТА СРОЧНО!!!!!!!!!!!!! нужно чтобы выводился последний элемент каждого листа

  Ответить  
Rambler's Top100
вверх

Rambler's Top100 Яндекс.Метрика Яндекс цитирования