how to delete repeated element in stack c 2b 2b

Solutions on MaxInterview for how to delete repeated element in stack c 2b 2b by the best coders in the world

showing results for - "how to delete repeated element in stack c 2b 2b"
Isabella
06 Mar 2016
1int* stack = (int*)malloc(10 * sizeof(int));
2int size = 10;
3int sp = -1;
4
5bool isempty() {
6    return (sp == -1);
7}
8
9bool isfull() {
10    return (sp == size - 1);
11}
12
13void push(int x) {
14    if (isfull()) {
15        printf("Full!");
16    }
17    else {
18        sp++;
19        stack[sp] = x;
20    }
21}
22
23int pop() {
24    int x;
25    if (isempty()) {
26        printf("Empty!");
27    }
28    else {
29        x = stack[sp];
30        sp--;
31    }
32    return x;
33}
34
35void peek() {
36    if (!isempty()) {
37        printf("%d", stack[sp]);
38    }
39}
40
41void clear() {
42    while (!isempty()) {
43        pop();
44    }
45}
46
47void print() {
48    if (!isempty()) {
49        for (int i = 0; i < sp+1; i++) {
50            printf("%d ", stack[i]);
51        }
52    }
53    printf("\n");
54}
55