Mam do napisania w C++ listę. Utworzyłem wszystko jako statyczne, bo będę używał tak czy siak tylko jednej instancji.
Oto nagłówek klasy List - list.h:
Kod: Zaznacz cały
#pragma once
class List
{
public:
class ogniwo
{
public:
static ogniwo * next;
static ogniwo * prev;
static int value;
};
class iterator
{
public:
static ogniwo * ptr;
// Returns a pointer to the next element
static iterator next(iterator it);
};
static List* list;
static int repeats,
size,
init_list_size,
HEIGHT,
WIDTH;
static double time_delete_first,
time_delete_last,
time_delete_random,
time_add_first,
time_add_last,
time_add_random;
static iterator first;
static iterator last;
/* iterator first; */
/* iterator last; */
// Constructor, creates a new list with 1 element with value v
List(int HEIGHT, int WIDTH, int v);
// Destructor
~List();
// Shows all values of the list
static void showAllValues();
// Adds new element with value v behind item indicated by its pointer
static iterator insert_list(iterator it, int v);
// Removes element indicated by it pointer
static iterator removeListItem(iterator it);
// Returns beginning of the list
static iterator begin();
// Returns end of the list
static iterator end();
// Returns true if value v in the list
static bool isInList(int v);
};
Kod: Zaznacz cały
#include <iostream>
#include <ncurses.h>
#include "List.h"
using namespace std;
/* initialization of variables */
int List::HEIGHT = 0;
int List::WIDTH = 0;
int List::repeats = 100;
int List::size = 0;
int List::init_list_size = 10000;
iterator List::first = ???
terator List::last = ???
double List::time_delete_first = 0;
double List::time_delete_last = 0;
double List::time_delete_random = 0;
double List::time_add_first = 0;
double List::time_add_last = 0;
double List::time_add_random = 0;
...
(dalej to już mało istotne)