Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Лабораторная работа 1. Новикова Екатерина Андреевна #28

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,592 changes: 9,592 additions & 0 deletions NovikovaEA/Lab1/gtest/gtest-all.cc

Large diffs are not rendered by default.

20,063 changes: 20,063 additions & 0 deletions NovikovaEA/Lab1/gtest/gtest.h

Large diffs are not rendered by default.

204 changes: 204 additions & 0 deletions NovikovaEA/Lab1/include/list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
#pragma once
#include "node.h"

template <class val>
class ringlist
{
private:
node<val>* head;
node<val>* current; //������� �������
node<val>* tail;
public:
ringlist();
ringlist(const ringlist<val> &l);
~ringlist();
void clean(); //�������� ������
void reset(); //current = head
void getnext(); //current �������� �� ���������
bool isended() const; //�������� �� �����
void delet(node<val> *l);
val & getdata() const;
node<val>* search(const val &d);
void insert_to_tail(const val &d); //������� � �����
void insert_up(const val &d); //������� � ������������� ������
bool operator==(const ringlist<val> &l) const; //��������� �������
const ringlist<val> & operator=(const ringlist<val> &l);
friend ostream& operator<<(ostream &out, const ringlist<val> &n)
{
node<val>* t = n.head->next;
if (t == n.head)
out << "0";
while (t != n.head)
{
out << t->data << " ";
t = t->next;
}
return out;
}
};

template<class val>
inline ringlist<val>::ringlist()
{
head = new node<val>();
tail = head;
head->next = head;
}

template<class val>
inline ringlist<val>::ringlist(const ringlist<val>& l)
{
head = new node<val>();
node<val>* t = head;
node<val>* tt = l.head->next;
while (tt != l.head)
{
t->next = new node<val>(tt->data);
tail = t->next;
t = t->next;
tt = tt->next;
}
tail->next = head;
}

template<class val>
inline ringlist<val>::~ringlist()
{
clean();
delete head;
}

template<class val>
inline void ringlist<val>::clean()
{
node<val>* t = head->next;
while (t != head)
{
node<val>* tt = t->next;
delete t;
t = tt;
}
head->next = head;
tail = head;
}

template<class val>
inline void ringlist<val>::delet(node<val> *l)//�������� ����� ������
{
node<val> *t = head;
while (t->next != l)
t = t->next;
t->next = l->next;
delete l;
}

template<class val>
inline void ringlist<val>::reset()
{
current = head;
}

template<class val>
inline void ringlist<val>::getnext()
{
current = current->next;
}

template<class val>
inline bool ringlist<val>::isended() const
{
return (current == head);
}

template<class val>
inline val & ringlist<val>::getdata() const
{
return current->data;
}

template<class val>
inline node<val>* ringlist<val>::search(const val &d)//����� ����� � ������ d
{
node<val>* t = head->next;
while ((t != head) && (t->data != d))
{
t = t->next;
}
if (t == head)
return NULL;
else
return t;
}

template<class val>
inline void ringlist<val>::insert_to_tail(const val & d)
{
node<val>* t = new node<val>(d);
tail->next = t;
tail = t;
tail->next = head;;
}

template<class val>
inline void ringlist<val>::insert_up(const val & d)
{
node<val>* t = new node<val>(d);
node<val>* tt = head->next;
node<val>* pred = head;
while ((tt != head) && (tt->data > d))
{
pred = tt;
tt = tt->next;
}
t->next = tt;
pred->next = t;
if (tt == head)
{
tail = t;
}
}

template<class val>
inline bool ringlist<val>::operator==(const ringlist<val> &l) const
{
bool flag = true;
if (this != &l)
{
node<val>* t = head->next;
node<val>* tt = l.head->next;
while (t->data == tt->data && t != head && tt != l.head)
{
t = t->next;
tt = tt->next;
}
if (t != head || tt != l.head)
flag = false;
}
return flag;
}

template<class val>
const ringlist<val> & ringlist<val>::operator=(const ringlist<val> &l)
{
clean();
head = new node<val>();
node<val>* t = head;
node<val>* tt = l.head->next;
tail = head;
while (tt != l.head)
{
t->next = new node<val>(tt->data);
tail = t->next;
t = t->next;
tt = tt->next;
}
tail->next = head;
return *this;
}







31 changes: 31 additions & 0 deletions NovikovaEA/Lab1/include/monom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "node.h"
#include "list.h"

class monom
{
public:
double coeff;
unsigned int abc;
monom(const double cf = 0.0, const unsigned int abc2 = 0);
monom(const monom &n);
monom(const string &s);
~monom() {}
const monom& operator=(const monom &m);
bool operator==(const monom &m) const;
bool operator!=(const monom &m) const;
bool operator<(const monom &m) const;
bool operator>(const monom &m) const;
monom operator*(const double d) const;
monom operator*(const monom &m) const;
friend monom operator*(const double d, const monom &m)
{
return (m*d);
}
friend ostream & operator<<(ostream &os, const monom &n);
};




63 changes: 63 additions & 0 deletions NovikovaEA/Lab1/include/node.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#pragma once
#include <stdlib.h>
#include <iostream>
#include <string>

using namespace std;

template <class val>
class node
{
public:
val data;
node<val>* next;
node()
{
next = NULL;
}
node(const node<val> &n);
node(const val & d);
~node()
{
}
const node<val>&operator=(const node<val> &n);
bool operator==(const node<val> &n) const;
friend ostream & operator<<(ostream &os, const node<val> &n)
{
os << n.data;
return os;
}
};

template<class val>
inline node<val>::node(const node<val> &n)
{
data = n.data;
next = n.next;
}

template<class val>
inline node<val>::node(const val &d)
{
data = d;
next = NULL;
}

template<class val>
inline const node<val>& node<val>::operator=(const node<val> &n)
{
data = n.data;
next = n.next;
return *this;
}

template<class val>
inline bool node<val>::operator==(const node<val>& n) const
{
if ((data == n.data) && (next == n.next))
return true;
else
return false;
}


32 changes: 32 additions & 0 deletions NovikovaEA/Lab1/include/polinom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "monom.h"

class polinom
{
ringlist<monom> pol;
public:
polinom() {}
polinom(const polinom &p);
polinom(const string &s);
~polinom() {}
const polinom& operator=(const polinom &p);
polinom operator+(const polinom &p) const;
polinom operator*(const polinom &p) const;
polinom operator*(const double d) const;
bool operator==(const polinom &p) const;
bool operator!=(const polinom &p) const;
friend polinom operator*(const double d, const polinom &p)
{
return (p*d);
}
friend ostream& operator<<(ostream& out, const polinom &p);
};

//double rank_number(const double a, const int i);
//double converter_in_number(const string &s);





55 changes: 55 additions & 0 deletions NovikovaEA/Lab1/include/postfix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
#pragma once
#include <string>
#include "list.h"

class monom
{
public:
double coeff;
unsigned int xyz;
monom(const double c = 0.0, const unsigned int w = 0);
monom(const monom &m);
monom(const string &s);
~monom() {}
const monom& operator=(const monom &m);
bool operator==(const monom &m) const;
bool operator!=(const monom &m) const;
bool operator<(const monom &m) const;
bool operator>(const monom &m) const;
monom operator*(const double d) const;
monom operator*(const monom &m) const;
friend ostream & operator<<(ostream &out, const monom &m)
{
out << m.coeff << " " << m.xyz;
return out;
}
friend monom operator*(const double d, const monom &m) { return (m*d); }
};

class polinom
{
ringlist<monom> pol;
public:
polinom() {}
polinom(const polinom &p);
polinom(const string &s);
~polinom() {}
const polinom& operator=(const polinom &p);
polinom operator+(const polinom &p) const;
polinom operator*(const polinom &p) const;
polinom operator*(const double d)const;
friend ostream & operator<<(ostream &out, const polinom &p)
{
out << p.pol;
return out;
}
friend polinom operator*(const double d, const polinom &p) { return (p*d); }
bool operator==(const polinom &p) const;
bool operator!=(const polinom &p) const;
};

double rank_number(const double a, const int i);
double converter_in_number(const string &s);

*/
Loading