Advertisement
Grossos

Unordered list returns non equal values of integer

Mar 26th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include<iostream>
  2. #include<windows.h>
  3. using namespace std;
  4.  
  5. void init();
  6. void push(int n);
  7. void list();
  8. void pop();
  9.  
  10. struct elem
  11. {   int key;
  12.     elem *next;
  13. } *start,*p,*q;
  14. elem* ordered(int index);
  15.  
  16. void init()
  17. {                          
  18.       start=NULL;
  19. }
  20. void push(int n)
  21. {                          
  22.       p=start;
  23.       start=new elem;
  24.       start->key=n;
  25.       start->next=p;
  26. }
  27. void list()
  28. {                              
  29.       p=start;
  30.       cout<<"\nЛист: ";
  31.       while(p){
  32.             cout<<p->key<<" ";
  33.             p=p->next;
  34.       }
  35.       cout<<endl<<endl;
  36. }
  37.  
  38. elem* ordered(int index)              
  39. {
  40.       p=start;
  41.  
  42.       while(index)
  43.       {
  44.             p=p->next;
  45.        index--;
  46.       }
  47.  
  48.       return p;
  49. }
  50. int size()                    
  51. {
  52.       p=start;
  53.       int sum=0;
  54.       while(p->next!=NULL)
  55.       {
  56.             sum++;
  57.             p=p->next;
  58.       }
  59.  
  60.       return sum+1;
  61.  
  62. }
  63. void pop()
  64. {                                      
  65.      
  66.       for(int i=0;i<size();i++)
  67. {                      
  68. for(int j=0;j<size();j++)
  69. {                          
  70.       if(i!=j)
  71.       {                        
  72.       if((ordered(i))->key==(ordered(j))->key)
  73.       {            
  74. break;
  75.       }
  76.       if(j==size()-1)
  77.          
  78.       {
  79.    cout<<ordered(i)->key;
  80. }
  81. }
  82. }
  83.  
  84.       }
  85.       }
  86.  
  87.  
  88. void main()
  89. {
  90. int n;
  91. init();
  92. SetConsoleCP(1251);SetConsoleOutputCP(1251);
  93. cout<<"Въведете число:\n";
  94. while(cin>>n&&n!=999)
  95. {
  96. push(n);
  97. }
  98. cout<<"\nЛист :";
  99. pop();
  100. system("pause");
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement