256 lines
8.3 KiB
C
256 lines
8.3 KiB
C
#include "General.h"
|
|
|
|
struct Graph
|
|
{
|
|
Data_Type info;
|
|
struct LLL * list;
|
|
};
|
|
|
|
struct Arc
|
|
{
|
|
int weight;
|
|
struct Graph * point;
|
|
};
|
|
|
|
typedef struct Graph Graph;
|
|
typedef struct Arc Arc;
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// JoinGraphDirectedWt
|
|
// -------------------
|
|
//
|
|
// General : the function adds an arc between two items with direction
|
|
// and weight to the arc
|
|
//
|
|
// Parameters : Graph * a - the first item
|
|
// Graph * b -the second item
|
|
// int weight - the weight of the arc to be added
|
|
//
|
|
// Return Value : Void
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programer : Cohen Idan
|
|
// Student No. : 211675038
|
|
// Date : 04.01.2020
|
|
//---------------------------------------------------------------------------------------
|
|
void JoinGraphDirectedWt(Graph * a, Graph * b, int weight)
|
|
{
|
|
Arc * arc = (Arc *)malloc(sizeof(Arc));
|
|
arc->point = b;
|
|
arc->weight = weight;
|
|
PushLLL(&a->list);
|
|
a->list->value = (Data_Type)(void *)arc;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// JoinGraphNonDirectedWt
|
|
// ----------------------
|
|
//
|
|
// General : adds an arc between two items for both direction with
|
|
// weight to it
|
|
//
|
|
// Parameters : Graph * a - the first item
|
|
// Graph * b -the second item
|
|
// int weight - the weight of the arc to be added
|
|
//
|
|
// Return Value : Void
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programer : Cohen Idan
|
|
// Student No. : 211675038
|
|
// Date : 04.01.2020
|
|
//---------------------------------------------------------------------------------------
|
|
void JoinGraphNonDirectedWt(Graph * a, Graph * b, int weight)
|
|
{
|
|
JoinGraphDirectedWt(a, b, weight);
|
|
JoinGraphDirectedWt(b, a, weight);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// JoinGraphDirected
|
|
// -----------------
|
|
//
|
|
// General : adds an arc between two items without weight(single
|
|
// direction)
|
|
//
|
|
// Parameters : Graph * a - the first item
|
|
// Graph * b -the second item
|
|
//
|
|
// Return Value : Void
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programer : Cohen Idan
|
|
// Student No. : 211675038
|
|
// Date : 04.01.2020
|
|
//---------------------------------------------------------------------------------------
|
|
void JoinGraphDirected(Graph * a, Graph * b)
|
|
{
|
|
JoinGraphDirectedWt(a, b, ZERO);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// JoinGraphNonDirected
|
|
// --------------------
|
|
//
|
|
// General : adds an arc between two items without weight.
|
|
//
|
|
// Parameters : Graph * a - the first item.
|
|
// Graph * b -the second item.
|
|
//
|
|
// Return Value : Void.
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programer : Cohen Idan
|
|
// Student No. : 211675038
|
|
// Date : 04.01.2020
|
|
//---------------------------------------------------------------------------------------
|
|
void JoinGraphNonDirected(Graph * a, Graph * b)
|
|
{
|
|
JoinGraphDirected(a, b);
|
|
JoinGraphDirected(b, a);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// RemoveGraphDirectedWt
|
|
// ---------------------
|
|
//
|
|
// General : removes an arc between two items in a graph with the
|
|
// weight of it(searches for a certain direction).
|
|
//
|
|
// Parameters : Graph * a - the first item.
|
|
// Graph * b -the second item.
|
|
// int weight - the weight of the arc to be removed.
|
|
//
|
|
// Return Value : Void.
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programer : Cohen Idan
|
|
// Student No. : 211675038
|
|
// Date : 04.01.2020
|
|
//---------------------------------------------------------------------------------------
|
|
void RemoveGraphDirectedWt(Graph * a, Graph * b, int weight)
|
|
{
|
|
LLL * temp = a->list;
|
|
if (temp == NULL)
|
|
{
|
|
|
|
}
|
|
else if (((Arc *)temp->value.pointer)->point == b &&
|
|
((Arc *)temp->value.pointer)->weight == weight)
|
|
{
|
|
PopLLL(&a->list);
|
|
}
|
|
else
|
|
{
|
|
while (temp->next && ((Arc *)temp->next->value.pointer)->point != b ||
|
|
((Arc *)temp->next->value.pointer)->weight != weight)
|
|
{
|
|
temp = temp->next;
|
|
}
|
|
if (temp->next)
|
|
{
|
|
DeleteAfterLLL(temp);
|
|
}
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// RemoveGraphDirected
|
|
// -------------------
|
|
//
|
|
// General : function removes arc between two items in a graph with a
|
|
// direction between them.
|
|
//
|
|
// Parameters : Graph * a - the first item.
|
|
// Graph * b -the second item.
|
|
//
|
|
// Return Value : Void.
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programer : Cohen Idan
|
|
// Student No. : 211675038
|
|
// Date : 04.01.2020
|
|
//---------------------------------------------------------------------------------------
|
|
void RemoveGraphDirected(Graph * a, Graph * b)
|
|
{
|
|
RemoveGraphDirectedWt(a, b, ZERO);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// RemoveGraphNonDirected
|
|
// ----------------------
|
|
//
|
|
// General : function removes arc between two items in a graph,
|
|
// when the arc doesnt have weight to it.
|
|
//
|
|
// Parameters : Graph * a - the first item.
|
|
// Graph * b -the second item.
|
|
//
|
|
// Return Value : Void
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programer : Cohen Idan
|
|
// Student No. : 211675038
|
|
// Date : 04.01.2020
|
|
//---------------------------------------------------------------------------------------
|
|
void RemoveGraphNonDirected(Graph * a, Graph * b)
|
|
{
|
|
RemoveGraphDirected(a ,b);
|
|
RemoveGraphDirected(b, a);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// RemoveGraphNonDirectedWt
|
|
// ------------------------
|
|
//
|
|
// General : the function removes a specific arc with a specific weight
|
|
// to it
|
|
//
|
|
// Parameters : Graph * a - the first item
|
|
// Graph * b -the second item
|
|
// int weight - the weight of the arc to be removed
|
|
//
|
|
// Return Value : Void
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programer : Cohen Idan
|
|
// Student No. : 211675038
|
|
// Date : 04.01.2020
|
|
//---------------------------------------------------------------------------------------
|
|
void RemoveGraphNonDirectedWt(Graph * a, Graph * b, int weight)
|
|
{
|
|
RemoveGraphDirectedWt(a ,b, weight);
|
|
RemoveGraphDirectedWt(b, a, weight);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// AdjacentGraph
|
|
// -------------
|
|
//
|
|
// General : Checks if a has direct access to b.
|
|
//
|
|
// Parameters : Graph * a - item to check if it is next to b
|
|
// Graph * b - item to check if it is next to a.
|
|
//
|
|
// Return Value : if Adjacent graph or not (true/false).
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programer : Cohen Idan
|
|
// Student No. : 211675038
|
|
// Date : 04.01.2020
|
|
//---------------------------------------------------------------------------------------
|
|
BOOLEAN AdjacentGraph(Graph * a, Graph * b)
|
|
{
|
|
LLL * temp = a->list;
|
|
while (temp && ((Arc *)temp->next->value.pointer)->point != b)
|
|
{
|
|
temp = temp->next;
|
|
}
|
|
return (((Arc *)temp->next->value.pointer)->point == b);
|
|
}
|
|
|
|
void main(void)
|
|
{
|
|
|
|
}
|