Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct element {
- int key;
- element*next;
- element*prev;
- }*spisyk1 = nullptr, *spisyk2 = nullptr, *kombiniran = nullptr;
- void list(element *& list)
- {
- if (list) {
- element *pointer = list;
- while (pointer) {
- cout << pointer->key << "\t";
- pointer = pointer->next;
- }
- }
- else
- cout << "\nPrazen spisyk!!";
- }
- void add_b(element*& list, int n)
- {
- element * pointer = list;
- list = new element;
- list->key = n;
- list->prev = nullptr;
- list->next = pointer;
- if (pointer)
- pointer->prev = list;
- }
- void add_e(element*& list, int n)
- {
- element *q = new element;
- q->next = nullptr;
- q->key = n;
- if (list) {
- element *pointer = list;
- while (pointer->next)
- pointer = pointer->next;
- pointer->next = q;
- q->prev = pointer;
- }
- else {
- list = q;
- q->prev = nullptr;
- }
- }
- int del_k(element *& list, int k)
- {
- if (list) {
- element *p = list;
- while (p->key != k && p->next)
- p = p->next;
- if (p->key == k) {
- if (list->key == k) {
- list = list->next;
- if (list)
- list->prev = nullptr;
- }
- else {
- p->prev->next = p->next;
- if (p->next)
- p->next->prev = p->prev;
- }
- delete p;
- return 1;
- }
- else {
- cout << "\nNqma kvo da trie !";
- return 0;
- }
- }
- else {
- cout << "\nPrazen spisyk";
- return 0;
- }
- }
- void kombinirane() {
- if (spisyk1 == nullptr || spisyk2 == nullptr) {
- cout << "Spisycite sa prazni";
- exit(0);
- }
- else {
- element *pomoshten;
- kombiniran = spisyk1;
- pomoshten = kombiniran;
- while (pomoshten->next != nullptr)
- pomoshten = pomoshten->next;
- pomoshten->next = spisyk2;
- spisyk2->prev = pomoshten;
- while (pomoshten->next != nullptr)
- pomoshten = pomoshten->next;
- }
- }
- int main()
- {
- add_b(spisyk1, 3);
- add_b(spisyk1, 7);
- add_b(spisyk1, 9);
- add_b(spisyk2, 5);
- add_b(spisyk2, 13);
- add_b(spisyk2, 20);
- cout << "Spisyk 1: \n";
- list(spisyk1);
- cout << "\n\nSpisyk 2: \n";
- list(spisyk2);
- cout << "\n\nKombiniran spisyk: \n";
- kombinirane();
- list(kombiniran);
- cout << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement