-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack_example.c
More file actions
93 lines (79 loc) · 1.63 KB
/
Copy pathstack_example.c
File metadata and controls
93 lines (79 loc) · 1.63 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
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int sayi;
struct node * next;
}node;
node *dugum=NULL;
int enKucuk;
void push(){
node *yeni=(node*)malloc(sizeof(node));
printf("Sayiyi giriniz:");
scanf("%d",¥i->sayi);
yeni->next=NULL;
if(dugum==NULL){
dugum=yeni;
enKucuk=dugum->sayi;
}
else{
if(yeni->sayi < enKucuk) enKucuk = yeni->sayi;
node *gezici=dugum;
while(gezici->next!=NULL)
gezici=gezici->next;
gezici->next=yeni;
}
}
void pop(){
if(dugum==NULL)
printf("Stackte eleman bulunmamaktadır lutfen eleman ekleyin.\n");
else{
node *gezici=dugum;
int nextMin=999999;
if(dugum->next==NULL){
printf("%d popped.\n",gezici->sayi);
dugum=NULL;
enKucuk=0;
}
else{
while(gezici->next->next!=NULL){
gezici=gezici->next;
if(gezici->sayi > enKucuk && gezici->sayi < nextMin) nextMin=gezici->sayi;
}
if(gezici->next->sayi==enKucuk) enKucuk=nextMin;
printf("%d popped.\n",gezici->next->sayi);
gezici->next=NULL;
}
}
}
void print_stack(){
if(dugum==NULL)
printf("Stack'te eleman bulunmamaktadır lutfen eleman ekleyin.\n");
else{
node *gezici=dugum;
while(gezici!=NULL){
printf("%d \n",gezici->sayi);
gezici=gezici->next;
}
}
}
int main(){
while(1){
printf("1)push\t2)pop\t3)print\t4)En Kucugu yazdir \nIslem seciniz:");
int secim;
scanf("%d",&secim);
switch(secim){
case 1:
push();
break;
case 2:
pop();
break;
case 3:
print_stack();
break;
case 4:
printf("En kucuk eleman:%d\n",enKucuk);
break;
}
}
}