What is the error in the program? I tried to run it on ideone, but its
giving runtime error.
This is a program to reverse a linked list.


#include<stdio.h>
#include<malloc.h>
int count=0;
struct try{

       int data;
       struct try *next;
};
typedef struct try node;
node *head,*head2;
void reverse(node *list, int k)
{
        if(!k)
{
head=list->next;
 return;
}
if(list->next==NULL)
                      return;
        reverse(list->next,k-1);
        if(k==1)
head2=list->next;
 list->next->next=list;

list->next=NULL;
 }

void add(node *list,int a)
{
     node *temp;
     temp=malloc(sizeof(node));
     temp->data=a;
     temp->next=NULL;
     if(list==NULL)
                   list=temp;
     else
     {
         temp->next=list;
         list=temp;
     }
}
void print(node *list)
{
     while(list->next!=NULL)
printf("%d",list->data);
}

void del(node *list)
{
     node *temp;
     while(list!=NULL)
     {
                    temp=list;
                    free(list);
                    list=temp->next;
     }
}

int main()
{
int k;
node *list;
 scanf("%d",&k);
list=NULL;
add(list,10);
 add(list,20);
add(list,30);
add(list,40);
 add(list,50);
add(list,60);

print(list);

reverse(list,k-1);
list->next=head;
print(head2);
 del(head2);
return 0;
}


-- 
Nikhil Gupta
Senior Co-ordinator, Publicity
CSI, NSIT Students' Branch
NSIT, New Delhi, India

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to