-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinklist.c
148 lines (109 loc) · 1.92 KB
/
linklist.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
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
146
147
148
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* Link;
};
struct Node* root=NULL;
void PrintList(){
if(root==NULL){
printf("liste bosss!");
return;
}
struct Node * n;
n=root;
while(n!=NULL){
printf("%d==>",n->data);
n=n->Link;
}
}
void ListeyeEkle(){
struct Node *temp =NULL;
temp=(struct Node*)malloc(sizeof(struct Node));
printf("liste elemaninin datasini giriniz!");
scanf("%d",&temp->data);
temp->Link=NULL;
if(root!=NULL)
{
root=temp;
}
else
{
struct Node* p;
p=root;
while(p->Link!=NULL)
{
p=p->Link;
}
p->Link=temp;
}
}
int LenghtList(){
int count=0;
if(root==NULL)
return count;
struct Node* temp;
temp=root;
while(temp!=NULL){
temp=temp->Link;
count++;
}
return count;
}
void ArayaEkle(){
int count =1;
int n;
int len=LenghtList;
printf("kacinci elemandan sonra deger ekleyeceksiniz: \n");
scanf("%d",&n);
temp=(struct Node*)malloc(sizeof(struct Node));
if(n>len){
printf("liste boyutu fazla!");
return;
}
if(n==len){
printf("git sola ekle");
}
if(n==1){
printf("root degismeli");
return;
}
struct Node * p;
struct Node* temp=NULL;
p = root;
while(count<n){
p=p->Link;
}
temp->data=100;
temp->Link=P->Link;
p->Link=temp;
}
int main(){
while(1){
int eleman;
int ch;
printf("\n1-eleman ekle\n");
printf("2-listeyi yazdir\n");
printf("3-liste boyutu\n");
printf("araya ekle\n");
printf("5-exit");
scanf("%d",&ch);
switch(ch){
case 1:
ListeyeEkle();
break;
case 2:
PrintList();
break;
case 3:
printf("liste boyutu =%d",LenghtList());
break;
case 4:
ArayaEkle();
break;
case 5:
return 0;
}
}
return 0;
}