Sei sulla pagina 1di 25

Member Contribution Report

Umie Aimah Jeffry Mohd. Khalid Iqbal Derek Tee Jia Chen
Linked list 100%
Stacks 50% 50%
Documentation 50% 50%
TOTAL : 100% 100% 100%
Table Of Content

1. Introduction
2. Explanations of data structure concepts implemented
i. Linked List
ii. Stacks
3. Output
i. Linked List
ii. Stacks
4. Conclusions
5. References
Introduction
Explanations of Data Structure Concepts
1. LINKED LIST

2. STACKS

This assignment required us to write a program for an automated stockroom. The retailer is
stored and retrieved from the stockroom using a computerized robotics system.

This is a sample coding to show how a stack would actually work and how the LIFO (Last In
First Out) protocol / rules is applied and followed. Also, how it is shown to be functioning
inside the program.

~5 different types of retailers which have 5 different storage bins.~

#include<stdio.h>

//Defining MAX as 5 is declaring the size of the stack will be 5, using index (0 - 4).

#define MAX 5

//Declaring the structures, which will be a used for the bins (Bin A - Bin E).

struct stack1

int stack1[MAX];

int top1;

}s1;

struct stack2

{
int stack2[MAX];

int top2;

}s2;

struct stack3

int stack3[MAX];

int top3;

}s3;

struct stack4

int stack4[MAX];

int top4;

}s4;

struct stack5

int stack5[MAX];

int top5;

}s5;

~PUSH is use to add a new node to the top of the stack.~ (Lecture5_Stacks; 2016)

~POP is used to remove a node from the top.~ (Lecture5_Stacks; 2016)


//void PUSH is a function for adding elements/items into the stacks/bins.

void PUSH();

//void POP is a function for removing elements/items into the stacks/bins.

void POP();

//void DISPLAY is a function for showing the status of the stack/bins whether they have
elements (current status) or empty.

void DISPLAY();

//void main is a function acting like a screen for the program.

void main()

int select;

//Declaring the stack for struct1 - struct5 (Bin A - Bin E) is empty.

s1.top1 = -1;

s2.top2 = -1;

s3.top3 = -1;

s4.top4 = -1;

s5.top5 = -1;
~Here, it ask user to choose whether they want to ADD, REMOVE or DISPLAY the input.
If not, they can exit / quit from the system.~

printf("-OPERATIONS OF STACK- \n");

while (select = 1)

printf("\n1. PUSH\n");

printf("2. POP\n");

printf("3. DISPLAY\n");

printf("4. EXIT\n");

printf("\nENTER YOUR CHOICE : ");

scanf("%d", &select);

//Switch is used to make selection for the following operations : PUSH, POP, DISPLAY and
EXIT.

switch (select)

case 1: PUSH();

break;

case 2: POP();

break;

case 3: DISPLAY();
break;

case 4: exit();

default:

printf("\nYOUR SELECTION IS INVALID. PLEASE RE-ENTER


YOUR INPUT.\n");

break;

~PUSH have been applied in the coding.~

//Function PUSH is to add elements into the stack using the Last In First Out (LIFO) order.

void PUSH()

int number;

int selectpush;

printf("\n1. BIN A\n");

printf("2. BIN B\n");

printf("3. BIN C\n");

printf("4. BIN D\n");

printf("5. BIN E\n");


~Here, they need to select which storage bin they want to store the input.~

printf("\nPLEASE SELECT THE BIN : ");

scanf("%d", &selectpush);

switch (selectpush)

case 1:

if (s1.top1 == MAX - 1)

printf("\nSTACK OVERFLOW (STACK IS FULL).\n");

else

printf("\nENTER ELEMENTS TO INSERT INTO THE STACK : ");

scanf("%d", &number);

s1.top1 = s1.top1 + 1;

s1.stack1[s1.top1] = number;

break;

case 2:
if (s2.top2 == MAX - 1)

printf("\nSTACK OVERFLOW (STACK IS FULL).\n");

else

printf("\nENTER ELEMENTS TO INSERT INTO THE STACK : ");

scanf("%d", &number);

s2.top2 = s2.top2 + 1;

s2.stack2[s2.top2] = number;

break;

case 3:

if (s3.top3 == MAX - 1)

printf("\nSTACK OVERFLOW (STACK IS FULL).\n");

else

printf("\nENTER ELEMENTS TO INSERT INTO THE STACK : ");

scanf("%d", &number);

s3.top3 = s3.top3 + 1;
s3.stack3[s3.top3] = number;

break;

case 4:

if (s4.top4 == MAX - 1)

printf("\nSTACK OVERFLOW (STACK IS FULL).\n");

else

printf("\nENTER ELEMENTS TO INSERT INTO THE STACK : ");

scanf("%d", &number);

s4.top4 = s4.top4 + 1;

s4.stack4[s4.top4] = number;

break;

case 5:

if (s5.top5 == MAX - 1)

printf("\nSTACK OVERFLOW (STACK IS FULL).\n");

else
{

printf("\nENTER ELEMENTS TO INSERT INTO THE STACK : ");

scanf("%d", &number);

s5.top5 = s5.top5 + 1;

s5.stack5[s5.top5] = number;

break;

default:

printf("\nYOUR SELECTION IS INVALID. PLEASE RE-ENTER YOUR


INPUT.\n");

break;

~POP have been applied.~

//Funtion POP is to delete elements from the stacks (Only removes the top most
elements/items on each stack).

void POP()

int number;

int selectpop;

printf("\n1. BIN A\n");


printf("2. BIN B\n");

printf("3. BIN C\n");

printf("4. BIN D\n");

printf("5. BIN E\n");

printf("\nPLEASE SELECT THE BIN : ");

scanf("%d", &selectpop);

~ If a new product needs to go into a bin that is full, the product that is on top of the bin is
removed and thrown away using the stack concept.~

switch (selectpop)

case 1:

if (s1.top1 == -1)

printf("\nSTACK IS UNDERFLOW (STACK IS EMPTY).\n");

else

number = s1.stack1[s1.top1];

s1.top1 = s1.top1 - 1;

printf("\nELEMENTS REMOVED FROM THE STACK IS : %d\n",


number);

}
break;

case 2:

if (s2.top2 == -1)

printf("\nSTACK IS UNDERFLOW (STACK IS EMPTY).\n");

else

number = s2.stack2[s2.top2];

s2.top2 = s2.top2 - 1;

printf("\nELEMENTS REMOVED FROM THE STACK IS : %d\n",


number);

break;

case 3:

if (s3.top3 == -1)

printf("\nSTACK IS UNDERFLOW (STACK IS EMPTY).n");

else

number = s3.stack3[s3.top3];

s3.top3 = s3.top3 - 1;
printf("\nELEMENTS REMOVED FROM THE STACK IS : %d\n",
number);

break;

case 4:

if (s4.top4 == -1)

printf("\nSTACK IS UNDERFLOW (STACK IS EMPTY).\n");

else

number = s4.stack4[s4.top4];

s4.top4 = s4.top4 - 1;

printf("\nELEMENTS REMOVED FROM THE STACK IS : %d\n",


number);

break;

case 5:

if (s5.top5 == -1)

printf("\nSTACK IS UNDERFLOW (STACK IS EMPTY).\n");

else
{

number = s5.stack5[s5.top5];

s5.top5 = s5.top5 - 1;

printf("\nELEMENTS REMOVED FROM THE STACK IS : %d\n",


number);

break;

default:

printf("\nYOUR SELECTION IS INVALID. PLEASE RE-ENTER YOUR


INPUT.\n");

break;

//Function DISPLAY is to display the current status of each stack when selected, whether it
shows the current elements/items in the stacks/bins or tells the user that it is empty.

void DISPLAY()

int i;

int number;

int selectdisplay;

printf("\n1. BIN A\n");


printf("2. BIN B\n");

printf("3. BIN C\n");

printf("4. BIN D\n");

printf("5. BIN E\n");

printf("\nPLEASE SELECT THE BIN : ");

scanf("%d", &selectdisplay);

switch (selectdisplay)

case 1:

if (s1.top1 == -1)

printf("\nSTACK IS UNDERFLOW (STACK IS EMPTY).\n");

else

printf("\nTHE STATUS OF THE STACK IS : ");

for (i = s1.top1; i >= 0; i--)

printf("%d ", s1.stack1[i]);

printf("\n");
}

break;

case 2:

if (s2.top2 == -1)

printf("\nSTACK IS UNDERFLOW (STACK IS


EMPTY).\n");

else

printf("\nTHE STATUS OF THE STACK IS : ");

for (i = s2.top2; i >= 0; i--)

printf("%d ", s2.stack2[i]);

printf("\n");

break;

case 3:

if (s3.top3 == -1)

printf("\nSTACK IS UNDERFLOW (STACK IS


EMPTY).\n");
}

else

printf("\nTHE STATUS OF THE STACK IS : ");

for (i = s3.top3; i >= 0; i--)

printf("%d ", s3.stack3[i]);

printf("\n");

break;

case 4:

if (s4.top4 == -1)

printf("\nSTACK IS UNDERFLOW (STACK IS


EMPTY).\n");

else

printf("\nTHE STATUS OF THE STACK IS : ");

for (i = s4.top4; i >= 0; i--)

printf("%d ", s4.stack4[i]);

}
printf("\n");

break;

case 5:

if (s5.top5 == -1)

printf("\nSTACK IS UNDERFLOW (STACK IS


EMPTY).\n");

else

printf("\nTHE STATUS OF THE STACK IS : ");

for (i = s5.top5; i >= 0; i--)

printf("%d ", s5.stack5[i]);

printf("\n");

break;

default:

printf("\nYOUR SELECTION IS INVALID. PLEASE RE-ENTER YOUR


INPUT.\n");

break;
}

Output
a) Stacks
1. Main Page

2. PUSH function output.


3. PUSH function when overflow the system will give a message Stack Overflow
(Stack is full) when the bin is full.

4. POP function output. this part is to show which data have been removed from the
bin. For example below, data 20 have been removed by user from the storage bin.
5. POP function when it is underflow or empty. the system will give a message Stack
is Underflow (Stack is Empty) when there is no data inside the bin.

6. DISPLAY function. the system will display / show all the data inside all of the bin,
Conclusion

In conclusion, we have write linked list coding that asks the user to enter items until the user
chooses to stop, stores them into list nodes, and chains the nodes together into a linked list. Our
main interface provide 4 menu for user to choose which is:

Add
Print / Display
Remove
Quit

All the data that already been insert will be arranged in alphabetical order.

While in stack coding, we write a program for an automated stockroom. We have used LIFO
(Last In First Out) protocol in PUSH and POP coding. If a new product needs to go into a bin
that is full, the product that is on top of the bin is removed and thrown away using the stack
concept.

The benefit of this system is to help the user to insert, store and remove the data / information.
The system also help the user to store data in ascending order so that it is easy to search and
read.

Other than that, we learn many things from this assignment such as how to write C
Programming for linked list and stacks.
REFERENCING

1. Lecture5_Stacks, 2016.
2. Gupta, N. and EngineersGarage (2012) User login. Available at:
http://www.engineersgarage.com/c-language-programs/stack-push-pop-
implementation-using-arrays (Accessed: 18 September 2016).
3. Lecture4_Dynamic_Data_Storage, 2016.
4. Switch statement in C (2016) Available at:
http://www.tutorialspoint.com/cprogramming/switch_statement_in_c.htm (Accessed:
18 September 2016).
5. Structures in C (2016) Available at:
http://www.tutorialspoint.com/cprogramming/c_structures.htm (Accessed: 18
September 2016).
6. Algogal (2014) C program to implement two stacks using a single array & check for
overflow & Underflow. Available at: http://www.sanfoundry.com/c-program-two-
stacks-single-array/ (Accessed: 18 September 2016).
7. Manish (2012) C program to implement a stack. Available at:
http://www.sanfoundry.com/c-program-stack-implementation/ (Accessed: 18
September 2016).
8.

Potrebbero piacerti anche