Created
November 24, 2014 22:01
-
-
Save cubuspl42/ae840e5d272eb4b058d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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