-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListaDwukierunkowa.cpp
More file actions
145 lines (129 loc) 路 2.94 KB
/
Copy pathListaDwukierunkowa.cpp
File metadata and controls
145 lines (129 loc) 路 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// Created by kukul on 08.11.2019.
//
#include "ListaDwukierunkowa.h"
#include <iostream>
using namespace std;
void ListaDwukierunkowa::insert(int x, int i, elem *&lista) {
if (i == 1)
{
elem* newElement = new elem;
newElement->dane = x;
newElement->nast = lista;
newElement->poprz = NULL;
lista = newElement;
}
else {
elem* temp = lista;
elem* poprzEl = NULL;
for (int b = 1; b < i; b++) {
poprzEl = temp;
temp = temp->nast;
}
elem* newElement = new elem;
newElement->dane = x;
if (temp != NULL) {
newElement->poprz = temp->poprz;
temp->poprz = newElement;
newElement->nast = temp;
}
else {
newElement->poprz = poprzEl;
newElement->nast = NULL;
}
poprzEl->nast = newElement;
}
}
void ListaDwukierunkowa::read(elem *lista) {
elem* pomocnicza = lista;
while (pomocnicza!=NULL){
cout << pomocnicza->dane << endl;
int x = pomocnicza->dane;
pomocnicza = pomocnicza->nast;
}
}
void remove(int i, elem*& lista) {
if (i == 1)
{
elem* wsk = lista;
lista = lista->nast;
if (lista != NULL)
lista->poprz = NULL;
delete wsk;
}
else
{
elem* temp = lista;
elem* before = NULL;
for (int j = 1; j < i; j++)
{
before = temp;
temp = temp->nast;
}
if (temp->nast != NULL) {
before->nast = temp->nast;
temp->nast->poprz = before;
delete temp;
}
else {
before->nast = NULL;
delete temp;
}
}
}
void reverse(elem*& lista)
{
elem* temp = lista;
while (temp)
{
elem* war2 = temp->nast;
temp->nast = temp->poprz;
temp->poprz = war2;
if (temp->poprz == NULL)
lista = temp;
temp = temp->poprz;
}
}
void to_cyclic(elem* lista)
{
elem* wskaznik = lista;
while (wskaznik->nast != NULL)
wskaznik = wskaznik->nast;
wskaznik->nast = lista;
}
void reverse_cyclic(elem* lista)
{
elem* temp = lista;
lista = lista->nast;
elem* temp2 = lista->nast;
while (temp != temp2)
{
lista->nast = temp;
temp = lista;
lista = temp2;
temp2 = lista->nast;
}
}
bool is_valid_pn(elem* lista)
{
if (lista == NULL)
return false;
int operands = 0;
while (lista != NULL)
{
if (lista->dane == '+' || lista->dane == '-' || lista->dane == '*' || lista->dane == '/')
{
operands--;
if (operands < 1)
{
return false;
}
}
else if (lista->dane >= 97 && lista->dane <= 122)
operands++;
else
return false;
lista = lista->nast;
}
return operands == 1;
}