Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
// izbir.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <new.h>
#include "string.h"
struct ElemType {float x1,x2;} ;
struct Cell
{
ElemType x;
Cell* Next;
};
class CList
{
Cell Head;
public:
CList();
~CList();
void Delete(Cell* pos);
Cell* End(void);
void MakeNull(void);
void end_insert(ElemType x);
void Show();
void Proizv();
};
CList::CList()
{
Head.Next=NULL;
};
CList::~CList()
{
// MakeNull();
};
void CList::Show()
{ Cell *temp_ptr = Head.Next;
if (temp_ptr == NULL) cout<<"Empty Node"<<endl;
else
while (temp_ptr != NULL)
{
cout<<temp_ptr->x.x1<<"x^"<<temp_ptr->x.x2<<"+";
temp_ptr=temp_ptr->Next;
}
cout<<endl;
}
void CList::Proizv()
{ Cell *temp_ptr = Head.Next;
if (temp_ptr == NULL) return;
else
while (temp_ptr != NULL)
{
temp_ptr->x.x1=temp_ptr->x.x1*temp_ptr->x.x2;
temp_ptr->x.x2=temp_ptr->x.x2-1;
temp_ptr=temp_ptr->Next;
}
cout<<endl;
}
void CList::end_insert (ElemType x)
{ Cell *tail=&Head; // ??®??
while(tail->Next!=NULL)
{tail=tail->Next;}
tail->Next=new Cell;
tail->Next->x=x;
tail->Next->Next=NULL;
//tail->link=tail1;
}
void CList::Delete(Cell* pos)
{
Cell* temp;
temp=pos->Next;
pos->Next=pos->Next->Next;
delete temp;
};
Cell* CList::End(void)
{ if(Head.Next!=NULL)
{
Cell* p=Head.Next;
while(p->Next->Next!=NULL) p=p->Next;
return p;
};
return NULL;
};
void CList::MakeNull()
{
while(End()!=NULL) Delete(End());
};
int main(int argc, char* argv[])
{
CList yravn;
ElemType s;
int i=1;
char choise;
cout<<"Vvod yravneniya"<<endl;
for(;;)
{
cout<<"c"<<i<<"=";
cin>>s.x1;
cout<<"e"<<i<<"=";
cin>>s.x2;
yravn.end_insert(s);
cout<<"Esche odin? N";
cin>>choise;
if (choise=='N') break;
}
yravn.Show();
yravn.Proizv();
yravn.Show();
return 0;
}