linked_list/linked_list1.cpp
// reversing a linked list
// in this we'll be using an auxillary array to reverse a linked list
reversing a linked list
in this we'll be using an auxillary array to reverse a linked list
reversing a linked list in this we ' ll be using an auxillary array to reverse a linked list
void reverse_linked_list_a(){
    Node *p = first;
    int *A;
    A = (int *)malloc(sizeof(int)*count_nodes(p));
    int i =0;
    while(p){
        A[i] = p->data;
        p=p->next;
        i++;
    }
    p=first;
    i--;
    while(p){
        p->data=A[i];
        p=p->next;
        i--;
    }
}
void reverse_linked_list_a ( ) { Node * p = first ; int * A ; A = ( int * ) malloc ( sizeof ( int ) * count_nodes ( p ) ) ; int i = 0 ; while ( p ) { A [ i ] = p -> data ; p = p -> next ; i ++ ; } p = first ; i -- ; while ( p ) { p -> data = A [ i ] ; p = p -> next ; i -- ; } }
reversing a linked list
in this we'll be using an auxillary array to reverse a linked list
reversing a linked list in this we ' ll be using an auxillary array to reverse a linked list
// pointer to an array // dynamicaly allocate memory to an array // until p becomes null // copy linked list data to the array // again start from first // point to end of the array // copy array data to linked list // in the reverse order // move p // move i backwards