Friday, 5 October 2012

STRING REVERSE BY DOUBLY LINK LIST

Q.)WAP TO REVERSE THE STRING USING LINK LIST .
SOLUTION)--

----***STRING REVERSE USING DOUBLY LINK LIST***----

#include
#include
#include
int main()
{
    struct node
    {
        char data;
        struct node *prev;
        struct node *next;
    }*head;
    char str[1000];
    head=NULL;
    int num,i;
    struct node *end,*temp;
    scanf("%s",str);
    num=strlen(str);
    for(i=0;i
    {
        if(head==NULL)
        {
            head=malloc(sizeof(struct node));
            head->data=str[i];
            temp=head;
            temp->prev=NULL;
        }
        else
        {
            temp->next=malloc(sizeof(struct node));
            temp->next->prev=temp;
            temp->next->data=str[i];
            temp=temp->next;
        }
    }
    temp->next=NULL;
    end=temp;
    temp=end;
    while(temp!=NULL)
    {
        printf("%c",temp->data);
        temp=temp->prev;
    }
    return 0;
}




No comments: