#include<iostream>
using namespace std;
struct Node {
double value;
Node* next;
Node();
Node(double value);
Node(const Node& n);
~Node();
//swap premješta sadržaj između dva čvora
void swap(Node& n);
void print();
};
Node::Node(){
next = nullptr;
}
Node::Node(double value){
this->value=value;
next = nullptr;
}
Node::Node(const Node& n){
value = n.value;
next = n.next;
}
Node::~Node(){}
void Node::swap(Node &n) {
double temp = value;
value = n.value;
n.value = temp;
}
void Node::print() {
cout << "Node at: " << this << "; value: " << value << "; next: " << next << endl;
}
class CSLL {
protected:
Node* head;
public:
CSLL();
CSLL(const CSLL& c);
~CSLL();
bool empty();
void prepend(double value);
void append(double value);
double removeFromHead();
void sort();
void print();
};
CSLL::CSLL() {
head = nullptr;
}
CSLL::CSLL(const CSLL &c) {
head = nullptr;
Node *it = c.head; //iterator
do{
append(it->value);
it = it->next;
}while(it!=c.head);
}
CSLL::~CSLL() {
while (!empty())
removeFromHead();
}
bool CSLL::empty() {
return head == nullptr;
}
void CSLL::prepend(double value) {
Node* n = new Node{value};
if (empty()){
n->next = n;
head = n;
}else{
Node* it = head;
while(it->next!=head)
it = it->next;
it->next = n;
n->next = head;
head = n;
}}
void CSLL::append(double value) {
prepend(value);
head = head->next;
}
double CSLL::removeFromHead() {
if (!empty()){
double to_return = head->value;
Node* to_delete = head;
Node* it = head;
while(it->next!=head)
it = it->next;
if (head==head->next){
}else{
it->next = head->next;
head = head->next;
}
delete to_delete;
return to_return;
}}
void CSLL::sort() {
Node* last = head;
while(last->next != head)
last = last->next;
while(last!=head){
Node* j= head;
Node* prev;
while(j!=last){
if(j->value > (j->next->value))
j->swap(*j->next);
prev = j;
j = j->next;
}
last = prev;
}
}
void CSLL::print() {
cout << "CSLL at: " << this << "; head at: " << head << endl;
if(!empty()){
Node* it = head;
do {
it->print();
it = it->next;
}while(it!=head);
}
cout << endl << endl;
}
class DynamicQueue {
protected:
CSLL container;
public:
DynamicQueue();
DynamicQueue(const DynamicQueue& q);
~DynamicQueue();
bool empty();
void enqueue(double x);
double dequeue();
void print();
};
int main(){
double arr[] = {59.9, 13.7, 10.0, 98.44, 16.7, 20.269, 1.5};
CSLL *c = new CSLL{};
c->print();
for (double el: arr)
c->append(el);
c->print();
CSLL *c2 = new CSLL{*c};
c2->print();
c2->sort();
c2->print();
c2->removeFromHead();
c2->print();
delete c; delete c2;
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}