doubly linked list reverse

my code is

#include<stdio.h>

struct node {
int info;
struct node *next, *prev;
};
typedef struct node *nodeptr;
nodeptr i;
nodeptr q;
nodeptr p;
nodeptr *plist;

nodeptr getnode(void)
{
nodeptr p;
p = (nodeptr) malloc(sizeof(struct node));
return p;
}

void freenode(nodeptr p)
{
free(p);
}





int main()
{
int i;
nodeptr *k;
int a;
int r;
nodeptr start;
nodeptr temp;
nodeptr e;
p = getnode();

q = start;


for (i = 0; i < 3; i++) {

printf("enter value");
scanf("%d", &r);
p = getnode();
p->info = r;
q->next = p;
e = q;
q = q->next;
temp = q;
temp->prev = e;

}

while (q->prev != NULL) {

printf("n%d", q->info);
q = q->prev;
}
return 0;
}

i have reversed a linked list it is reversing but additional two elements 0,0 are coming can yu suggest whats going wrong
Topic archived. No new replies allowed.