-
Notifications
You must be signed in to change notification settings - Fork 0
/
belajar.cpp
76 lines (70 loc) · 1.36 KB
/
belajar.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>
struct book{
char studentname[30];
struct book *next, *prev;
}*head, *tail, *current;
void print(){
if(head!=NULL){
current=head;
while(current!=NULL){
printf("%s -> ", current->studentname);
current=current->next;
}
}else{
printf("No Data");
}
printf("\n\n");
};
void pushHead(char name[]){
current = (struct book *)malloc(sizeof book);
strcpy(current->studentname, name);
current->next = current->prev = NULL;
if(head==NULL){
head=tail=current;
}else{
head->prev=current;
current->next=head;
head=current;
}
}
void popHead(){
if(head==NULL){
printf("No Data");
}else if(head==tail){
current=head;
head=tail=NULL;
free(current);
}else{
current=head;
head=head->next;
head->prev=NULL;
free(current);
}
}
void main(){
int menu;
char studentname[30];
print();
do{
do{
system("cls");
print();
printf("1. Stack\n");
printf("2. UnStack\n");
printf("3. Exit\n");
printf("Choose : "); scanf("%d", &menu); fflush(stdin);
}while(menu<1 || menu>3);
switch(menu){
case 1 :
printf("Input Student Name : "); scanf("%s", studentname); fflush(stdin);
pushHead(studentname);
break;
case 2 :
popHead();
break;
}
}while(menu!=3);
}