Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication72.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct elem //????????? ?? ???????
- {
- int key; //????????
- elem *next; //??????? ???????
- }*start;
- int counter = 0; //????? ???? ?? ????? ????????
- int value = 0; //????????? ?? ????????
- //?????????? ?? ?????????
- void init();
- void add_e(int n);
- int search_el(int n);
- void print_list();
- void del_e(int &n);
- void main()
- {
- init(); //?????????????
- cout << "Vavedete chisla za spisaka (0 za kraj): ";
- int number = -1;
- while (true) //????????? ?? ??????? ????????? ?? ???? ????
- {
- cin >> number;
- if (number == 0) //???? ?? ?????? ?? ????????? ??? ??????? ? 0
- {
- break;
- }
- add_e(number); //???????? ?? ???????? ??????? ? ???????
- }
- elem *p1 = start; //???????? (????? ?? ? ??????)
- while (p1->next) //?? ????? ??????? ?? ???????
- {
- search_el(p1->key); //??????? ????? ???? ?? ????? ? ????????? ??
- if (counter > 1) {
- del_e(value);
- }
- //??????????:
- counter = 0;
- value = 0;
- if (p1->next)
- {
- p1 = p1->next; //??????? ??? ????????? ???????
- }
- }
- //????????? ?? ?????????:
- print_list();
- }
- void init() //?????????????
- {
- start = NULL;
- }
- void add_e(int n) //???????? ?? ???????? ? ???? (???????)
- {
- elem *p = start, *q;
- q = new elem;
- q->key = n;
- q->next = NULL;
- if (start)
- {
- while (p->next)
- p = p->next;
- p->next = q;
- }
- else
- {
- start = q;
- }
- }
- void del_e(int &n)
- {
- elem *p = start;
- if (start)
- {
- while (true)
- {
- if (p->key == n)
- {
- p->key = NULL;
- }
- if (p->next == NULL)
- {
- break;
- }
- p = p->next;
- }
- }
- }
- int search_el(int n) //??????? ?? ??????? ? ?????? ?? ???? ???????? ? ?????????? ??.
- {
- elem *p = start;
- if (start)
- {
- while (true)
- {
- if (p->key == n)
- {
- counter++;
- value = n;
- }
- if (p->next == NULL)
- {
- break;
- }
- p = p->next;
- }
- }
- return 0;
- }
- void print_list()
- {
- elem *p = start;
- if (start)
- {
- cout << "Elementite na spisaka sa: \n";
- while (p)
- {
- if (p->key != NULL) {
- cout << p->key << "\t";
- }
- p = p->next;
- }
- cout << endl;
- }
- else
- cout << "Nqma elementi v spisaka.";
- }
Advertisement
Add Comment
Please, Sign In to add comment