Please do not change the functions below. This should be coded in C language. Al
ID: 3856295 • Letter: P
Question
Please do not change the functions below. This should be coded in C language. Also malloc should occur in addInt function.
Use the following structure definition to make a stack:
typedef struct Integer_
{
int num;
struct Integer_* nextInt;
struct Integer_* prevInt;
} Integer;
You will make a simple stack using a linked list. This linked list will have pointers pointing both ways so that we can get to the bottom of the stack if we need to, but also just keep track of the top of the stack since that is where we are adding nodes. In the real world, you will likely keep track of both the top and bottom using a pointer for each, but for this, we will just keep track of the top.
Make sure you don’t screw up your list! You need to hook up the prevInt pointer as well as the nextInt pointer. Make sure the bottom of the stack also has a prevInt value set as well. What should it be?
Use the following function prototypes:
Integer* addInt(Integer*, Integer*);
Adds an integer to the stack. Returns the new top of the stack. Malloc memory
void printNumbers(Integer*);
Prints out all numbers, starting with the BOTTOM of the stack. Be careful! The pointer passed is pointing to the top of the stack.
void freeNumbers(Integer*);
Frees all nodes, starting with the top of the stack.
Integer* deleteInt(Integer*);
Deletes an integer from the stack. Returns the new top of the stack.
Sample Output
Select an option:
1: add a number
2: take a number off
3: print numbers
4: quit
Option:
>1
Insert your Number: 10
Select an option:
1: add a number
2: take a number off
3: print numbers
4: quit
Option:
>1
Insert your Number: 11
Select an option:
1: add a number
2: take a number off
3: print numbers
4: quit
Option:
>1
Insert your Number: 12
Select an option:
1: add a number
2: take a number off
3: print numbers
4: quit
Option:
>3
10->11->12
Select an option:
1: add a number
2: take a number off
3: print numbers
4: quit
Option:
>2
Select an option:
1: add a number
2: take a number off
3: print numbers
4: quit
Option:
>3
10->11
Select an option:
1: add a number
2: take a number off
3: print numbers
4: quit
Option:
>4
Explanation / Answer
#include <stdio.h>
typedef struct person
{
int age;
float weight;
};
int main()
{
struct person *personPtr, person1;
personPtr = &person1; // Referencing pointer to memory address of person1
printf("Enter integer: ");
scanf("%d",&(*personPtr).age);
printf("Enter number: ");
scanf("%f",&(*personPtr).weight);
printf("Displaying: ");
printf("%d%f",(*personPtr).age,(*personPtr).weight);
return 0;
}