Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack1.c
More file actions
Latest commit
46 lines (41 loc) · 992 Bytes
/
Copy pathstack1.c
File metadata and controls
46 lines (41 loc) · 992 Bytes
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
/* Name: Vishwa Venkateshwaran */
#include<stdio.h>
#include<stdlib.h>
#include"lab4.h"
Stack*newStack1() {
Stack*Stack=malloc(sizeof(Stack));
Stack1*stack1=malloc(sizeof(Stack1));
if (Stack) {
Stack->Stack=stack1;
Stack->length=lengthS1;
Stack->push=pushS1;
Stack->pop=popS1;
stack1->length=0;
}
returnStack;
}
voidpushS1(void*pointer, intdata) {
Stack1*stack1= (Stack1*) pointer;
LLNode*newNode=malloc(sizeof(LLNode));
if(stack1->firstNode) {
newNode->next=stack1->firstNode;
} else {
stack1->lastNode=newNode;
}
stack1->firstNode=newNode;
stack1->length++;
newNode->data=data;
}
intpopS1(void*pointer) {
Stack1*stack1= (Stack1*) pointer;
LLNode*returningNode=stack1->firstNode;
intdata=stack1->firstNode->data;
free(returningNode);
stack1->firstNode=stack1->firstNode->next;
stack1->length--;
returndata;
}
intlengthS1(void*pointer) {
Stack1*stack1= (Stack1*) pointer;
returnstack1->length;
}