First Upload
This commit is contained in:
56
16 - Stack/ex4.c
Normal file
56
16 - Stack/ex4.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "Lib.h"
|
||||
|
||||
#define MAX 21
|
||||
|
||||
typedef struct
|
||||
{
|
||||
string name;
|
||||
unsigned int amount;
|
||||
} VegBox;
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// AddBox
|
||||
// -------
|
||||
//
|
||||
// General : The function added new box to the tower of boxes in some Circumstances.
|
||||
//
|
||||
// Parameters : Tower - A stack with boxes inside.(in)
|
||||
// box - A item from the type VegBox that needed to be add to the tower.
|
||||
//
|
||||
// Return Value : None.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programer : Cohen Idan
|
||||
// Student No. : 211675038
|
||||
// Date : 05.12.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void AddBox(stack * sk, VegBox vb)
|
||||
{
|
||||
Data_Type item = PopStack(sk);
|
||||
Data_Type new_item;
|
||||
stack temp_sk;
|
||||
InitializeStack(&temp_sk);
|
||||
while (!IsEmptyStack(sk) && !StringCompare((*(VegBox *)(item.pointer)).name, vb.name))
|
||||
{
|
||||
item = PopStack(sk);
|
||||
PushStack(&temp_sk, item);
|
||||
}
|
||||
if (!StringCompare((*(VegBox *)(item.pointer)).name, vb.name))
|
||||
{
|
||||
while ((*(VegBox *)(item.pointer)).amount++ < MAX && vb.amount-- > ZERO);
|
||||
}
|
||||
while (!IsEmptyStack(&temp_sk))
|
||||
{
|
||||
PushStack(sk, PopStack(&temp_sk));
|
||||
}
|
||||
if (vb.amount > ZERO)
|
||||
{
|
||||
*(VegBox * )new_item.pointer = vb;
|
||||
PushStack(sk, new_item);
|
||||
}
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user