-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.c
89 lines (74 loc) · 1.62 KB
/
stack.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
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include"kdTree.h"
#include"stack.h"
#include"helper.h"
#define N 1000
extern int k;
extern int count;
extern int t;
extern int target[N];
extern int c1,c2;
struct node_in *create_data(int arr[])
{
struct node_in *temp = (struct node_in *)calloc(1, sizeof(struct node_in));
temp->point = calloc(k, sizeof(int));
for (int i = 0; i < k; i++){
temp->point[i] = arr[i];
}
return temp;
}
// Function to push node in the custom stack
void push(int arr[])
{
if (top == NULL)
{
top = (struct node_s *)malloc(1 * sizeof(struct node_s));
top->next = NULL;
top->info = create_data(arr);
}
else
{
temp = (struct node_s *)malloc(1 * sizeof(struct node_s));
temp->next = top;
temp->info = create_data(arr);
top = temp;
}
count++;
}
// Function to pop a node in custom stack
void pop()
{
top1 = top;
if (top1 == NULL)
{
printf("Stack is empty \n");
return;
}
for (int i = 0; i < k; i++)
{
printf("%d ", top1->info->point[i]);
}
printf("\n");
push_to_array(top1->info->point[k-1]);
top1 = top1->next;
top = top1;
count--;
}
// dislaying the elements of stack
void display()
{
top1 = top;
if (top1 == NULL)
{
printf("Stack is empty");
return;
}
while (top1 != NULL)
{
for (int i = 0; i < k; i++)
printf("%d \n", top1->info->point[i]);
top1 = top1->next;
}
}