Created
August 25, 2011 22:43
-
-
Save gertcuykens/1172221 to your computer and use it in GitHub Desktop.
.gcc
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<stdio.h> | |
#include<stdlib.h> | |
struct item | |
{ | |
int v; | |
struct item *next; | |
struct item *prev; | |
}; | |
void main() | |
{ | |
struct item *new=NULL, *curr=NULL, *tail=NULL; | |
int i; | |
curr = malloc(sizeof(struct item)); | |
(*curr).v = 1; | |
(*curr).prev = NULL; | |
(*curr).next = NULL; | |
tail = curr; | |
for(i=2;i<=10;i++) | |
{ | |
new = malloc(sizeof(struct item)); | |
(*new).v = i; | |
(*new).prev = curr; | |
(*new).next = NULL; | |
(*curr).next = new; | |
curr = new; | |
} | |
(*curr).next = tail; | |
(*tail).prev = curr; | |
for(i=0;i<=100;i++) | |
{ | |
printf("%d\n", (*curr).v); | |
curr = (*curr).prev; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment