From dd35265470c4d9cd3dc359bdc1fc8f77bb638792 Mon Sep 17 00:00:00 2001 From: Erge-S <82161070+Erge-S@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:02:32 +0300 Subject: [PATCH] Add files via upload --- Lsn9AlS.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 Lsn9AlS.c diff --git a/Lsn9AlS.c b/Lsn9AlS.c new file mode 100644 index 0000000..b95fc73 --- /dev/null +++ b/Lsn9AlS.c @@ -0,0 +1,173 @@ +#include +#include +#include +#define true 1 == 1 +#define false 1 != 1 +#define T char +typedef int boolean; +const int n=6; +int matrix [6][6]= +{ + {0,1,1,0,0,0}, + {0,0,0,1,1,1}, + {0,0,0,0,0,1}, + {1,0,0,0,0,0}, + {0,0,0,0,0,0}, + {0,0,0,0,1,0} +}; +int visited[6]={0}; +typedef struct TwoLinkNode { + int dat; + struct TwoLinkNode *next; + struct TwoLinkNode *prev; +} TwoLinkNode; + +typedef struct { + struct TwoLinkNode *head; + struct TwoLinkNode *tail; + int size; +} TwoLinkList; + +void deepTR(int st) +{ + int r; + printf("%d ",st); + visited[st]=1; + for (r=0;rhead = NULL; + lst->tail = NULL; + lst->size = 0; +} +void clearVis(int* arr,int size) +{ + for (int i=0;idat = value; + tmp->next = NULL; + tmp->prev = queue->tail; + + if (queue->tail != NULL) { + queue->tail->next = tmp; + } + if (queue->head == NULL) { + queue->head = tmp; + } + + queue->tail = tmp; + queue->size++; + return true; +} +T TwoLinkDequeue(TwoLinkList *queue) { + if (queue->size == 0) { + printf("Queue is empty \n"); + return -1; + } + TwoLinkNode *tmp = queue->head; + T data = queue->head->dat; + + queue->head = queue->head->next; + + if (queue->head != NULL) { + queue->head->prev = NULL; + } + if (tmp == queue->tail) { + queue->tail = NULL; + } + + free(tmp); + queue->size--; + return data; +} +int get2dInt(int** array, const int row, const int col) { + return *((*(array + row)) + col);} +int** init2dIntArray(int** array, const int row, const int col) { + array = (int**) calloc(sizeof(int*), row); + for (int i = 0; i < row; ++i) { + *(array + i) = (int*) calloc(sizeof(int), col); + } + return array; +} +void set2dInt(int** array, const int row, const int col, int value) { + *((*(array + row)) + col) = value; +} + +int widthTR(int**matrix,int start,const int size) +{ + TwoLinkList*queve=(TwoLinkList*) malloc(sizeof(TwoLinkList)); + initTwoLinkList(queve); + int visited[size]; + clearVis(visited,size); + TwoLinkEnqueue(queve,size); + while(queve->size>0) + { + int index=TwoLinkDequeue(queve); + if (visited[index]==1) continue; + visited[index]=1; + printf("%d",index); + for (int i=0;i