예 : "This is an This"로 바꿔야합니다. 한 문자는 각 노드의 정보로 저장해야합니다. 이렇게하면 전체 문장을 뒤집을 수 있습니다 (즉, "elpmaxe na si sihT").연결된 목록에서 문장의 단어를 바꾸는 방법은 무엇입니까?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node {
struct node *ptr;
char info;
};
struct node *first,*ic;
struct node * insertn(int n,struct node * first)
{
struct node *temp,*cur;
temp=(struct node *)malloc(sizeof(struct node));
temp->info=n;
temp->ptr='\0';
if(first=='\0')
{
return temp;
}
else{
cur=first;
while(cur->ptr!='\0')
cur=cur->ptr;
cur->ptr=temp;
return first;
}
}
void disp(struct node *first)
{
printf("here");
struct node *cur;
cur=first;
while(cur!='\0')
{
printf("%c",cur->info);
cur=cur->ptr;
}
}
void rev(struct node * p)
{
if(p->ptr=='\0')
{
first =p;
return;
}
rev(p->ptr);
struct node *q=p->ptr;
q->ptr=p;
p->ptr='\0';
}
main()
{
char n;
int i=0;
first='\0';
ic='\0';
while(i<7)
{
i++;
printf("Enter element:");
scanf("%c",&n);
first=insertn(n,first);
}
printf("ELEMENTS OF LIST BEFORE REV:");
disp(first);
rev(first);
printf("\n\nELEMENTS OF LIST AFTER REV:");
disp(first);
}
시작 "예를 들어이입니다". –