Phoenix_x

Untitled

Apr 4th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. // ConsoleApplication72.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. struct elem //????????? ?? ???????
  9. {
  10.     int key; //????????
  11.     elem *next; //??????? ???????
  12. }*start;
  13.  
  14. int counter = 0; //????? ???? ?? ????? ????????
  15. int value = 0; //????????? ?? ????????
  16.  
  17.                //?????????? ?? ?????????
  18. void init();
  19. void add_e(int n);
  20. int search_el(int n);
  21. void print_list();
  22. void del_e(int &n);
  23.  
  24. void main()
  25. {
  26.     init(); //?????????????
  27.     cout << "Vavedete chisla za spisaka (0 za kraj): ";
  28.     int number = -1;
  29.  
  30.     while (true) //????????? ?? ??????? ????????? ?? ???? ????
  31.     {
  32.         cin >> number;
  33.  
  34.         if (number == 0) //???? ?? ?????? ?? ????????? ??? ??????? ? 0
  35.         {
  36.             break;
  37.         }
  38.  
  39.         add_e(number); //???????? ?? ???????? ??????? ? ???????
  40.     }
  41.  
  42.     elem *p1 = start; //???????? (????? ?? ? ??????)
  43.  
  44.     while (p1->next) //?? ????? ??????? ?? ???????
  45.     {
  46.         search_el(p1->key); //??????? ????? ???? ?? ????? ? ????????? ??
  47.  
  48.         if (counter > 1) {
  49.             del_e(value);
  50.         }
  51.  
  52.         //??????????:
  53.         counter = 0;
  54.         value = 0;
  55.  
  56.         if (p1->next)
  57.         {
  58.             p1 = p1->next; //??????? ??? ????????? ???????
  59.         }
  60.     }
  61.  
  62.     //????????? ?? ?????????:
  63.     print_list();
  64. }
  65.  
  66. void init() //?????????????
  67. {
  68.     start = NULL;
  69. }
  70.  
  71.  
  72. void add_e(int n) //???????? ?? ???????? ? ???? (???????)
  73. {
  74.     elem *p = start, *q;
  75.     q = new elem;
  76.     q->key = n;
  77.     q->next = NULL;
  78.     if (start)
  79.     {
  80.         while (p->next)
  81.             p = p->next;
  82.         p->next = q;
  83.     }
  84.     else
  85.     {
  86.         start = q;
  87.     }
  88. }
  89.  
  90. void del_e(int &n)
  91. {
  92.     elem *p = start;
  93.     if (start)
  94.     {
  95.         while (true)
  96.         {
  97.             if (p->key == n)
  98.             {
  99.                 p->key = NULL;
  100.             }
  101.  
  102.             if (p->next == NULL)
  103.             {
  104.                 break;
  105.             }
  106.  
  107.             p = p->next;
  108.         }
  109.     }
  110. }
  111.  
  112. int search_el(int n) //??????? ?? ??????? ? ?????? ?? ???? ???????? ? ?????????? ??.
  113. {
  114.     elem *p = start;
  115.     if (start)
  116.     {
  117.         while (true)
  118.         {
  119.             if (p->key == n)
  120.             {
  121.                 counter++;
  122.                 value = n;
  123.             }
  124.  
  125.             if (p->next == NULL)
  126.             {
  127.                 break;
  128.             }
  129.  
  130.             p = p->next;
  131.         }
  132.     }
  133.     return 0;
  134. }
  135.  
  136. void print_list()
  137. {
  138.     elem *p = start;
  139.  
  140.     if (start)
  141.     {
  142.         cout << "Elementite na spisaka sa: \n";
  143.  
  144.         while (p)
  145.         {
  146.             if (p->key != NULL) {
  147.                 cout << p->key << "\t";
  148.             }
  149.             p = p->next;
  150.         }
  151.         cout << endl;
  152.     }
  153.     else
  154.         cout << "Nqma elementi v spisaka.";
  155. }
Advertisement
Add Comment
Please, Sign In to add comment