typedef struct node *linklist;
//revese linklist
linklist reverselinklist1(linklist l) {
linklist current, p;
if(l == NULL) {
return NULL;
}
current = l -> next;
while(current -> next != NULL) {
p = current -> next;
current -> next = p -> next;
p -> next = l -> next;
l -> next = p;
}
return l;
}
linklist reverselinklist2(linklist l) {
linklist current, p;
if(l == NULL) {
return NULL;
}
current = l -> next;
while(current -> next != NULL) {
p = current -> next;
l -> next = p;
current -> next = p -> next;
p -> next = current;
}
}
linklist reverselinklist3(linklist l) {
linklist newlist, temp;
newlist = (linklist)malloc(sizeof(struct node));
if(l == NULL || newlist == NULL) {
return NULL;
}
newlist -> data = l -> data;
newlist -> next = NULL;
while(l -> next != NULL) {
temp = newlist -> next;
newlist -> next = l -> next;
l -> next = l -> next -> next;
newlist -> next -> next = temp;
}
free(l);
return newlist;
}