Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- struct node
- {
- int data;
- node *next;
- };
- bool checknode(node *&head, int value)
- {
- while(head != NULL)
- {
- if(head->data == value)
- return false;
- head = head->next;
- }
- return true;
- }
- void printing(node *&head)
- {
- while(head != NULL)
- {
- if(head->data == 13)
- cout << "K ";
- else if(head->data == 12)
- cout << "Q ";
- else if(head->data == 11)
- cout << "J ";
- else if(head->data == 1)
- cout << "A ";
- else
- cout << head->data << " ";
- head = head->next;
- }
- cout << endl;
- }
- int main()
- {
- node *head=0;
- node *temp=0;
- node *hold=0;
- node *check=0;
- bool count;
- int x,i;
- hold = new node();
- hold->data = rand() % 13 + 1;
- head = hold; // head stays at the same place
- check = hold; // move around for checking
- temp = hold;
- // making unsorted list
- for(i=1; i<13; ++i)
- {
- x = rand() % 13 + 1;
- count = checknode(check,x);
- if(count == true)
- {
- hold = new node();
- hold->data = x;
- temp->next = hold;
- temp = temp->next;
- }
- else
- --i;
- check = head;
- count = true;
- }
- temp = head; // temp node for moving around
- hold = head;
- printing(hold);
- hold = head;
- int number,card=13;
- for(;;)
- {
- if(temp->data != card)
- {
- hold = temp;
- for(i=13-card; i<13; ++i)
- {
- if(i == 13-card)
- number = check->data;
- if(i != 12)
- check->data = check->next->data;
- else
- check->data = number;
- check = check->next;
- }
- check = temp;
- printing(hold);
- }
- else
- {
- temp = temp->next;
- hold = temp;
- printing(hold);
- check = temp;
- card -= 1;
- }
- if(temp == NULL)
- break;
- }
- delete hold,temp,head,check;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement