Skip to content

Instantly share code, notes, and snippets.

@cubuspl42
Created November 24, 2014 22:01
Show Gist options
  • Save cubuspl42/ae840e5d272eb4b058d4 to your computer and use it in GitHub Desktop.
Save cubuspl42/ae840e5d272eb4b058d4 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct lista {
int wartosc;
lista *next;
lista *prev;
};
void add_after(lista *l, int n) {
lista *x = new lista;
x->wartosc = n;
x->next = l->next;
if(l->next)
(l->next)->prev = x;
l->next = x;
x->prev = l;
return;
}
void init(lista *head) {
head->wartosc = -1;
head->next = NULL;
head->prev = NULL;
return;
}
int main() {
lista moja_lista;
init(&moja_lista);
lista *back = NULL;
back = &moja_lista;
for(int i = 0; i < 8; ++i) {
add_after(back, i);
back = back->next;
}
back = &moja_lista;
while(back) {
cout << back->wartosc << endl;
back = back->next;
}
return 0;
}
/*
Output:
-1
0
1
2
3
4
5
6
7
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment