-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinkedlist_sirali.cpp
More file actions
71 lines (64 loc) · 1.48 KB
/
linkedlist_sirali.cpp
File metadata and controls
71 lines (64 loc) · 1.48 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
/* NOTES:
listeler sequential(sıralı erişim), diziler ramdom
*/
#include "stdio.h"
#include "stdlib.h"
struct Node{
int data;
Node *next;
};
typedef Node node;
//fonksiyon prototipleri
void Display(node *toor);
void AddLast(node *toor, int value);
node *AddSequential(node *toor, int value);
int main(int argc, char const *argv[]) {
node *root;
root=NULL;
root=AddSequential(root,16);
root=AddSequential(root,22);
root=AddSequential(root,12);
root=AddSequential(root,18);
Display(root);
return 0;
}
void Display(node *toor){
while (toor != NULL) {
printf("-->%d", toor->data);
toor=toor->next;
}
}
//Listenin sonun eleman ekle
void AddLast(node *toor, int value) {
while (toor->next != NULL) {
toor=toor->next;
}
toor->next= (node *)malloc(sizeof(node));
toor->next->data= value;
toor->next->next=NULL;
}
//sıralı ekleme
node *AddSequential(node *toor, int value) {
if (toor == NULL) { //liste boşsa
toor=(node *)malloc(sizeof(node));
toor->next=NULL;
toor->data=value;
return toor;
}
if (toor->data > value) { //ilk eleman kücük durumu
node *temp = (node *)malloc(sizeof(node));
temp->data=value;
temp->next=toor;
return temp;
}
//diğer durumlar için
node *iterator=toor;
while (iterator->next != NULL && iterator->next->data < value) {
iterator=iterator->next;
}
node *temp = (node *)malloc(sizeof(node));
temp->next=iterator->next;
iterator->next=temp;
temp->data=value;
return toor;
}