#include #include 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; }