-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplelisttwoways.c
86 lines (80 loc) · 1.76 KB
/
simplelisttwoways.c
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
// nodelergerili.cpp : Bu dosya 'main' işlevi içeriyor. Program yürütme orada başlayıp biter.
//
#include <iostream>
#include <cstdlib>
#define NULL 0
using namespace std;
struct nodes {
nodes* back;
int val;
nodes* next;
};
nodes* root;
nodes* iter = root;
void node_Add() {
if (root == NULL) {
root = new nodes;
cout << "enter a val for node which is first : " << endl;
int b = 0;
cin >> b;
root->val = b;
root->back = NULL;
root->next = NULL;
}
else {
iter = root;
while (iter->next != NULL) {
iter = iter->next;
}
iter->next = new nodes;
cout << "enter a val for the node which is not first : " << endl;
int a = 0;
cin >> a;
iter->next->val = a;
iter->next->next = NULL;
iter->next->back = iter;
}
}
void delete_Nodes() {
iter = root;
if (root == NULL) {
cout << "no nodes to delete" << endl;
}
else if (root->next == NULL) {
delete(root);
root = NULL;
cout << "there was onl 1 item and it's being deleted" << endl;
}
else {
while (iter->next->next != NULL) {
iter = iter->next;
}
delete(iter->next);
iter->next = NULL;
cout << "item is being deleted" << endl;
}
}
int i = 1;
void node_Print() {
if (root == NULL) {
cout<< "no nodes yet" << endl;
}
else {
iter = root;
while (iter != NULL) {
cout << i << ". elemanin degeri : " << iter->val << endl;
i++;
iter = iter->next;
}
}
}
int main()
{
node_Add();
node_Add();
node_Add();
node_Add();
node_Print();
delete_Nodes();
node_Print();
}