reversing linked list

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;
nodeptr j;
nodeptr o;
nodeptr head;
nodeptr prev;
nodeptr h;
int a;
int u;
int v;
int w;
int *px;
int r;
nodeptr end;
nodeptr s;
nodeptr temp;
nodeptr start;
p=getnode();

q=start;



for(i=0; i<6; i++)
{
printf("enter value");
scanf("%d",&r);
p=getnode();
p->info=r;

q->next=p;
q=q->next;

}
q=start;
while(q->next!=NULL)

{
temp=q->next;
q->next=q->prev;
q->prev=temp;
q=q->prev;
}



while((q->next)!=NULL)
{
printf("\n%d",(q->next)->info);
q=q->next;
}
return 0;


can yu tell me what is wrong and how to correct it i have to reverse a linked list
Sorry, I'm not going to try to read that unformatted, un [code]code-blocked[/code] stuff... [edit] Not right now, that is... I'm tired...

Best way to start is to get out a piece of paper and a crayon (or a pen, if you want to be all intellectual about it ;-) and draw yourself a linked list.

Then draw what you have to do to reverse it. You can do it in a single pass -- starting at the first node and working your way to the end, building the new list as you go.

Good luck!
Last edited on
Topic archived. No new replies allowed.