Skip to content

Commit 3d9bc90

Browse files
committed
trouble with efficiency
1 parent 1b9ee55 commit 3d9bc90

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

sum.c

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <math.h>
4+
#include <stdlib.h>
5+
#define MAX 100001
6+
typedef struct node
7+
{
8+
int data;
9+
struct node* previous;
10+
}NODE;
11+
12+
typedef struct head
13+
{
14+
int size;
15+
NODE* top;
16+
}STACK;
17+
18+
STACK* init_list()
19+
{
20+
STACK* new_head = (STACK*) malloc(sizeof(STACK));
21+
new_head->top = NULL;
22+
new_head->size = 0;
23+
return new_head;
24+
}
25+
int isEmpty(STACK* top)
26+
{
27+
return(top->size == 0);
28+
}
29+
void push(STACK* stack, int item)
30+
{
31+
NODE* new_top = (NODE*) malloc(sizeof(NODE*));
32+
new_top->data = item;
33+
if(isEmpty(stack))
34+
{
35+
new_top->previous = NULL;
36+
}
37+
else
38+
{
39+
new_top->previous = stack->top;
40+
}
41+
stack->size++;
42+
stack->top = new_top;
43+
}
44+
STACK* pop(STACK* stack)
45+
{
46+
NODE* popped = stack->top;
47+
if(isEmpty(stack))
48+
{
49+
return NULL;
50+
}
51+
popped->previous == NULL;
52+
stack->top = stack->top->previous;
53+
stack->size--;
54+
55+
return popped;
56+
}
57+
58+
int main() {
59+
STACK* x = init_list();
60+
STACK* y = init_list();
61+
STACK* z = init_list();
62+
int eof_seeker;
63+
int len1= 0;
64+
int len2 = 0;
65+
int X[MAX];
66+
int Y[MAX];
67+
do //gets the first number
68+
{
69+
eof_seeker = scanf("%d", &X[len1]);
70+
if (eof_seeker != EOF)
71+
{
72+
push(x,X[len1]);
73+
len1++;
74+
}
75+
76+
} while (eof_seeker != EOF);
77+
do //gets the second number
78+
{
79+
eof_seeker = scanf("%d", &Y[len2]);
80+
if (eof_seeker != EOF)
81+
{
82+
push(y,Y[len2]);
83+
len2++;
84+
}
85+
86+
} while (eof_seeker != EOF);
87+
88+
89+
return 0;
90+
}

0 commit comments

Comments
 (0)