Добавил:
Upload
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
#include <iostream>
#include "list.h"
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
using namespace std;
Node::Node()
{
data=0;
next=0;
}
Node::Node(double &data, Node* next)
{
this->data=data;
this->next=next;
}
list::list()
{
head=0;
nodes=0;
}
list::~list()
{
}
int list::size1()
{
return nodes;
}
bool list::empty1()
{
return nodes==0;
}
Node* list::create(double value)
{
head=new Node(value);
nodes++;
return head;
}
Node* list::insert1(double value, Node* where)
{
Node* insNode;
insNode=new Node(value);
insNode->next=where->next;
where->next=insNode;
nodes++;
return insNode;
}
int list::max_element1()
{
Node *p = head; //cout<<head->next;
int max1 = INT_MAX;
while (p)
{
if (p->data > max1)
{
max1=p->data;
//cout<<p->data<<endl;
}
p=p->next;
}
cout << "The max_element in data is: " << max1 << endl;
}
void list::remove1(Node* where)
{
if(nodes>1 && where->next!=0)
{
Node* temp=new Node;
temp=where->next;
where->next=where->next->next;
delete temp;
nodes--;
}
}
void list::clear()
{
//cout << "123";
Node *node = head;//текущий заголовок
while (node!=0)//пока не дошли до конца списка
{
remove1(head); //удаляум из памяти найденый узел
node=node->next;
}
nodes--;
}
void list::print()
{
if(nodes==0)
cout << "list's empty" << endl;
else
{
Node* pNode=head;
for(int i=0; i<nodes; i++)
{
cout << "\ndata = " << pNode->data << "\nnext = " << pNode->next;
pNode=pNode->next;
}
}
}