Advertisement
dsdeep

Palindrome

Oct 12th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. void palindromeCheck(){
  2.     int c=countElement();
  3.     node *list=h,*revlist;
  4.     revlist=NULL;
  5.     int i=1;
  6.     while(list){
  7.             if(i>=((c/2)+2)&&i<=c){
  8.        node *tmp=(node*)malloc(sizeof(node));
  9.         tmp->d=list->d;
  10.         tmp->p=revlist;
  11.         revlist=tmp;
  12.         }
  13.         list=list->p;
  14.         i++;
  15.     }
  16.         list=h,i=0;
  17.     int count=0;
  18.     while(i!=(c/2)){
  19.         if((list->d)==(revlist->d)){
  20.             count++;
  21.         }
  22.         list=list->p;
  23.            node *tmp=revlist;
  24.         revlist=revlist->p;
  25.         free(tmp);
  26.         i++;
  27.     }
  28.     if(count==(c/2))
  29.         printf("Palindrome Found\n");
  30.     else
  31.         printf("Not Found\n");
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement