Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5.  
  6. struct node
  7. {
  8. int data;
  9. node *next;
  10. };
  11.  
  12. bool checknode(node *&head, int value)
  13. {
  14. while(head != NULL)
  15. {
  16. if(head->data == value)
  17. return false;
  18. head = head->next;
  19. }
  20. return true;
  21. }
  22.  
  23. void printing(node *&head)
  24. {
  25. while(head != NULL)
  26. {
  27. if(head->data == 13)
  28. cout << "K ";
  29. else if(head->data == 12)
  30. cout << "Q ";
  31. else if(head->data == 11)
  32. cout << "J ";
  33. else if(head->data == 1)
  34. cout << "A ";
  35. else
  36. cout << head->data << " ";
  37. head = head->next;
  38. }
  39. cout << endl;
  40. }
  41.  
  42. int main()
  43. {
  44. node *head=0;
  45. node *temp=0;
  46. node *hold=0;
  47. node *check=0;
  48. bool count;
  49. int x,i;
  50.  
  51. hold = new node();
  52. hold->data = rand() % 13 + 1;
  53. head = hold; // head stays at the same place
  54. check = hold; // move around for checking
  55. temp = hold;
  56.  
  57. // making unsorted list
  58. for(i=1; i<13; ++i)
  59. {
  60. x = rand() % 13 + 1;
  61. count = checknode(check,x);
  62. if(count == true)
  63. {
  64. hold = new node();
  65. hold->data = x;
  66. temp->next = hold;
  67. temp = temp->next;
  68. }
  69. else
  70. --i;
  71. check = head;
  72. count = true;
  73. }
  74. temp = head; // temp node for moving around
  75. hold = head;
  76.  
  77. printing(hold);
  78. hold = head;
  79. int number,card=13;
  80. for(;;)
  81. {
  82. if(temp->data != card)
  83. {
  84. hold = temp;
  85. for(i=13-card; i<13; ++i)
  86. {
  87. if(i == 13-card)
  88. number = check->data;
  89. if(i != 12)
  90. check->data = check->next->data;
  91. else
  92. check->data = number;
  93. check = check->next;
  94. }
  95. check = temp;
  96. printing(hold);
  97. }
  98. else
  99. {
  100. temp = temp->next;
  101. hold = temp;
  102. printing(hold);
  103. check = temp;
  104. card -= 1;
  105. }
  106. if(temp == NULL)
  107. break;
  108. }
  109.  
  110. delete hold,temp,head,check;
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement