Advertisement
Farhana_Zaman

ffgh

Jun 3rd, 2022
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct node
  4. {
  5. int value;
  6. struct node *blink;
  7. struct node *flink;
  8. };
  9. int n;
  10. node a[100];
  11. node *p=&a[0];
  12. void input()
  13. {
  14. cout<<"Enter the number of inputs:";
  15. cin>>n;
  16. cout<<"Enter the values:";
  17. for(int i=0;i<n;i++)
  18. {
  19. int x;
  20. cin>>x;
  21. a[i].value=x;
  22. if(i+1!=n)
  23. a[i].flink=&a[i+1];
  24. if(i!=0)
  25. a[i].blink=&a[i-1];
  26. }
  27. a[0].blink=NULL;
  28. a[n-1].flink=NULL;
  29. }
  30. void calc()
  31. {
  32. int l=0;
  33. node *start=p;
  34. node *last=&a[n-1];
  35. while(start!=NULL)
  36. {
  37. if(last->value!=start->value)
  38. {
  39. l=1;
  40. break;
  41. }
  42. last=last->blink;
  43. start=start->flink;
  44. }
  45. if(l==0)
  46. cout<<"True"<<endl;
  47. else
  48. cout<<"False"<<endl;
  49. }
  50. int main ()
  51. {
  52. input();
  53. calc();
  54. return 0;
  55. }
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement