#include <iostream>
#include <string>
using namespace std;
struct ele {
int dana;
ele * nast;
ele * poprz;
};
void insert(ele* &head, ele* &tail, int x){
ele* nowy = new ele {x,NULL, NULL};
cout << "Dodalem: " << x << endl;
if(head==NULL){
head = nowy;
tail = nowy;
return;
}
nowy->poprz = tail;
tail->nast = nowy;
tail = nowy;
}
void removeFirst(ele* &head, ele* &tail){
if(head == NULL){
cout << "Lista pusta" << endl;
return;
}
else{
ele* temp = head;
head = head->nast;
cout << "Usunalem: " << temp->dana << endl;
delete temp;
temp = NULL;
return;
}
}
void remove(ele* &head, ele* &tail, int i){
ele* temp = head;
if(head == NULL){
return;
}
if(i == 0){
head = head->nast;
delete temp;
temp = NULL;
return;
}
else{
int j = 0;
while (j!=i){
j++;
temp=temp->nast;
}
temp->poprz->nast =temp->nast;
temp->nast->poprz = temp->poprz;
delete temp;
temp = NULL;
return;
}
}
void display(ele* &head, ele* &tail){
if(head == NULL){
cout << "Lista pusta";
}
ele* temp = head;
while(temp){
cout << temp->dana << " ";
temp=temp->nast;
}
}
int main(int argc, char** argv) {
ele* head = NULL;
ele* tail = NULL;
insert(head, tail, 5);
insert(head, tail, 10);
insert(head, tail, 15);
insert(head, tail, 20);
remove(head, tail, 2);
remove(head, tail, 0);
cout << "Lista: ";
display(head, tail);
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"}