First Upload
This commit is contained in:
1925
16 - Stack/Lib.h
Normal file
1925
16 - Stack/Lib.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
16 - Stack/ex1
Normal file
BIN
16 - Stack/ex1
Normal file
Binary file not shown.
72
16 - Stack/ex1.c
Normal file
72
16 - Stack/ex1.c
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "Lib.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exc1a
|
||||
// -----
|
||||
//
|
||||
// General : The function checks when the order in the stack is turn over.
|
||||
//
|
||||
// Parameters : s - A stack with numbers inside.(in)
|
||||
//
|
||||
// Return Value : The value in the stack when the order is turned over.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programer : Cohen Idan
|
||||
// Student No. : 211675038
|
||||
// Date : 05.12.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
int SectionOne(stack * sk)
|
||||
{
|
||||
stack temp_sk;
|
||||
InitializeStack(&temp_sk);
|
||||
CopyStack(&temp_sk, sk);
|
||||
int last_number = PopStack(&temp_sk).int_;
|
||||
int this_number = PopStack(&temp_sk).int_;
|
||||
while (this_number >= last_number)
|
||||
{
|
||||
last_number = this_number;
|
||||
this_number = PopStack(&temp_sk).int_;
|
||||
}
|
||||
|
||||
return (this_number);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exc1b
|
||||
// -----
|
||||
//
|
||||
// General : The function checks when the order in the stack is turn over.
|
||||
//
|
||||
// Parameters : s - A stack with numbers inside.(in)
|
||||
//
|
||||
// Return Value : The position in the stack when the order is turned over.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programer : Cohen Idan
|
||||
// Student No. : 211675038
|
||||
// Date : 05.12.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
int SectionOne(stack * sk)
|
||||
{
|
||||
stack temp_sk;
|
||||
InitializeStack(&temp_sk);
|
||||
CopyStack(&temp_sk, sk);
|
||||
unsigned int counter = ZERO;
|
||||
int number = SectionOne(&temp_sk);
|
||||
while (PopStack(&temp_sk).int_ != number)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
|
||||
return (counter);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
stack s;
|
||||
InitializeStack(&s);
|
||||
Data_Type num1 = {.int_ = 4}, num2 = {.int_ = 5}, num3 = {.int_ = 6};
|
||||
PushStack(&s, num1);
|
||||
PushStack(&s, num2);
|
||||
PushStack(&s, num3);
|
||||
}
|
||||
0
16 - Stack/ex2.c
Normal file
0
16 - Stack/ex2.c
Normal file
62
16 - Stack/ex3.c
Normal file
62
16 - Stack/ex3.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "Lib.h"
|
||||
|
||||
void DeleteItem(stack * sk, Data_Type item)
|
||||
{
|
||||
Data_Type temp_item;
|
||||
stack temp_sk;
|
||||
InitializeStack(&temp_sk);
|
||||
while (!IsEmptyStack(sk))
|
||||
{
|
||||
temp_item = PopStack(sk);
|
||||
if (temp_item.int_ != item.int_)
|
||||
{
|
||||
PushStack(&temp_sk, temp_item);
|
||||
}
|
||||
}
|
||||
while (!IsEmptyStack(&temp_sk))
|
||||
{
|
||||
PushStack(sk, PopStack(&temp_sk));
|
||||
}
|
||||
}
|
||||
|
||||
void DeleteDuplicates(stack * sk)
|
||||
{
|
||||
Data_Type item;
|
||||
stack temp_sk;
|
||||
InitializeStack(&temp_sk);
|
||||
while (!IsEmptyStack(sk))
|
||||
{
|
||||
item = PopStack(sk);
|
||||
DeleteItem(sk, item);
|
||||
PushStack(&temp_sk, item);
|
||||
}
|
||||
while (!IsEmptyStack(&temp_sk))
|
||||
{
|
||||
PushStack(sk, PopStack(&temp_sk));
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exc3
|
||||
// ----
|
||||
//
|
||||
// General : The function delete the duplicate numbers from the stack.
|
||||
//
|
||||
// Parameters : s - A stack with numbers inside.(in)
|
||||
//
|
||||
// Return Value : The stack without the duplicated numbers.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programer : Cohen Idan
|
||||
// Student No. : 211675038
|
||||
// Date : 05.12.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
stack s;
|
||||
InitializeStack(&s);
|
||||
Data_Type num1 = {.int_ = 4}, num2 = {.int_ = 5}, num3 = {.int_ = 6};
|
||||
PushStack(&s, num1);
|
||||
PushStack(&s, num2);
|
||||
PushStack(&s, num3);
|
||||
}
|
||||
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