Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include "list.h"
- Flowlist::Flowlist(): headM(0)
- {
- }
- /*
- void Flowlist::Flowlist(const Flowlist& rhs)
- {
- copy(source);
- }
- */
- /*
- Flowlist::~Flowlist()
- {
- destroy();
- }
- */
- void Flowlist::insert(Node *input)
- {
- search = headM;
- if(headM == 0 || input->flow<= headM->flow)
- {
- input->next = headM;
- headM = input;
- }
- else
- {
- Node *before = headM;
- Node *after = headM->next;
- while (after != 0 && input->flow > after->flow)
- {
- before = after;
- after = after ->next;
- }
- input->next = after;
- before-> next = input;
- }
- }
- Node* Flowlist::read_item(int n)
- {
- search = headM;
- for(int i=0; i < n; i++)
- {
- search = search->next;
- }
- return search;
- }
- /*
- int Flowlist::get_item()
- {
- int y , z;
- double w;
- node *x;
- x = read_item(const Flow&, int n);
- w = x->ListItem->flow;
- z= x->ListItem->year;
- return
- }
- */
- int Flowlist::get_year(int n)
- {
- search = headM;
- for(int i=0; i < n; i++)
- {
- search = search->next;
- }
- return search->year;
- }
- double Flowlist::get_flow(int n)
- {
- search = headM;
- for(int i=0; i < n; i++)
- {
- search = search->next;
- }
- return search->flow;
- }
- //set functions
- /*
- void Flowlist::Flowlist::operator=(const Flowlist& rhs)
- {
- if (this!= &rhs)
- {
- destroy();
- copy(rhs);
- }
- return *this;
- }
- */
- /*
- bool Flowlist::check(int y)
- {
- search = headM;
- while(search !=0)
- {
- search = search->next;
- }
- }
- */
- bool Flowlist::year_exists(int y)
- {
- search = find_year(y);
- if(search == NULL)
- return false;
- return true;
- }
- void Flowlist::remove(int y)
- {
- if ((headM == 0 )||(y < headM->year))
- return;
- Node *doomed_node = 0;
- if (y == headM->year)
- {
- doomed_node = headM;
- headM = headM->next;
- }
- else
- {
- Node *before = headM;
- Node *maybe_doomed = headM->next;
- while(maybe_doomed != 0 && y > maybe_doomed->year) {
- before = maybe_doomed;
- maybe_doomed = maybe_doomed->next;
- }
- if(maybe_doomed->year == y)
- {
- before->next = maybe_doomed->next;
- doomed_node = maybe_doomed;
- }
- }
- delete doomed_node;
- return;
- }
- Node* Flowlist::find_year(int y)
- {
- int i = 0;
- search = headM;
- while(search != 0)
- {
- int x = get_year(i);
- if (x == y)
- {
- break;
- }
- search = search->next;
- i++;
- }
- return search;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement