Program Discussion :: Linked List
95 / 16
Write a program to reverse the string using linked list
Answer:
#include "stdio.h"
#include "string.h"
#include "malloc.h"
#include
using namespace std;
typedef struct Rev{
char a;
struct Rev *link;
}Rev;
int main(){
Rev *head=NULL,*temp=NULL,*temp1=NULL,*temp2=NULL;
char b[20];
int i,j=0,len;
coutlink=NULL;
}
else
{
temp=head;
while(temp->link != NULL){
temp=temp->link;
}
temp->link=(Rev *)malloc(sizeof(Rev));
temp->link->link=NULL;
temp->link->a=b[i];
}
}
for(i=0;i
temp1=head;
temp2=temp1->link;
if(temp2 != NULL){
while(temp2->link != NULL){
temp2=temp2->link;
temp1=temp1->link;
}
coutlink=NULL;
}
else
{
cout
Asked In ::
Language:
Sneha Rai
7 Jul, 2017 9:30 AM
#include "stdio.h"
#include "string.h"
#include "malloc.h"
typedef struct Rev{
char a;
struct Rev *link;
}Rev;
int main(){
Rev *head=NULL,*temp=NULL,*temp1=NULL,*temp2=NULL;
char b[20];
int i,j=0,len;
printf("Enter a String: ");
gets(b);
len=strlen(b);
for(i=0;i
if(head==NULL){
head=(Rev *)malloc(sizeof(Rev));
head->a=b[i];
head->link=NULL;
}
else
{
temp=head;
while(temp->link != NULL){
temp=temp->link;
}
temp->link=(Rev *)malloc(sizeof(Rev));
temp->link->link=NULL;
temp->link->a=b[i];
}
}
for(i=0;i
temp1=head;
temp2=temp1->link;
if(temp2 != NULL){
while(temp2->link != NULL){
temp2=temp2->link;
temp1=temp1->link;
}
printf("%c",temp2->a);
temp1->link=NULL;
}
else
{
printf("%c",temp1->a);
}
}
return 0;
}
Language:
Aarav
7 Jul, 2017 9:30 AM
#include "stdio.h"
#include "string.h"
#include "malloc.h"
#include<iostream>
using namespace std;
typedef struct Rev{
char a;
struct Rev *link;
}Rev;
int main(){
Rev *head=NULL,*temp=NULL,*temp1=NULL,*temp2=NULL;
char b[20];
int i,j=0,len;
cout<<"Enter a String: ";
gets(b);
len=strlen(b);
for(i=0;i
if(head==NULL){
head=(Rev *)malloc(sizeof(Rev));
head->a=b[i];
head->link=NULL;
}
else
{
temp=head;
while(temp->link != NULL){
temp=temp->link;
}
temp->link=(Rev *)malloc(sizeof(Rev));
temp->link->link=NULL;
temp->link->a=b[i];
}
}
for(i=0;i
temp1=head;
temp2=temp1->link;
if(temp2 != NULL){
while(temp2->link != NULL){
temp2=temp2->link;
temp1=temp1->link;
}
cout<<temp2->a;
temp1->link=NULL;
}
else
{
cout<<temp1->a;
}
}
return 0;
}