Skip to content

Instantly share code, notes, and snippets.

@gertcuykens
Created August 25, 2011 22:43
Show Gist options
  • Save gertcuykens/1172221 to your computer and use it in GitHub Desktop.
Save gertcuykens/1172221 to your computer and use it in GitHub Desktop.
.gcc
#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