Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct str
- {
- char x;
- struct str *nast, *poprz;
- };
- typedef struct str EL;
- typedef EL *WSK;
- int palindrom(WSK lista)
- {
- WSK temp1=lista;
- WSK temp2=lista;
- while(temp2->nast!=NULL)
- {
- temp2=temp2->nast;
- }
- while(temp1)
- {
- if(temp1->x != temp2->x)
- return 0;
- temp1=temp1->nast;
- temp2=temp2->poprz;
- }
- return 1;
- }
- void wstaw(WSK *x, WSK nowy)
- {
- WSK temp=*x;
- nowy->nast=NULL;
- if(*x==NULL)
- {
- *x=nowy;
- (*x)->poprz=NULL;
- return 0;
- }
- while(temp->nast)
- {
- temp=temp->nast;
- }
- temp->nast=nowy;
- nowy->poprz=temp;
- return 0;
- }
- int main()
- {
- WSK lista=NULL;
- WSK nowy=(WSK)malloc(sizeof(EL));
- while(scanf("%c",&(nowy->x)))
- {
- if(nowy->x == '\n') break;
- wstaw(&lista,nowy);
- nowy=(WSK)malloc(sizeof(EL));
- }
- WSK temp=lista;
- while(lista)
- {
- printf("%c",lista->x);
- lista=lista->nast;
- }
- /* while(lista)
- {
- lista=lista->nast;
- if(lista->nast == 0)
- {
- while(lista->poprz != 0)
- {
- printf("%c",lista->x);
- lista=lista->poprz;
- }
- break;
- }
- } */
- palindrom(temp);
- }
Add Comment
Please, Sign In to add comment