Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Node{
- int data;
- Node *link;
- };
- Node *head=NULL;
- void insertEnd (int d)
- {
- Node *ptr = new Node();
- ptr->data=d;
- ptr->link=NULL;
- if(head==NULL)
- head=ptr;
- else
- {
- Node *temp = head;
- while(temp->link != NULL)
- {
- temp=temp->link;
- }
- temp->link=ptr;
- }
- }
- void insertFacNumberAndShoe(int facShoe){
- while(facShoe){
- insertEnd(facShoe%10);
- facShoe/=10;
- }
- }
- void sortAsc(){
- Node *current = head;
- while(current->link!=NULL){
- Node *n = current->link;
- Node *indexrazmqna = n;
- int tmp = n->data;
- while(n->link!=NULL){
- if(n->data<tmp){
- tmp = n->data;
- indexrazmqna = n;
- }
- n = n->link;
- }
- if(tmp<current->data){
- indexrazmqna->data = current->data;
- current->data = tmp;
- }
- current = current->link;
- }
- }
- void dispLink()
- {
- Node *temp=head;
- while(temp!=NULL)
- {
- cout<<temp->data<<" ";
- temp=temp->link;
- }
- cout<<"\n";
- }
- int main()
- {
- insertFacNumberAndShoe(9201043);
- sortAsc();
- dispLink();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement