From 1b0e08a5a70441f2dffea724d438b1fba9c84d68 Mon Sep 17 00:00:00 2001 From: Erge-S <82161070+Erge-S@users.noreply.github.com> Date: Fri, 14 Oct 2022 00:05:53 +0300 Subject: [PATCH] Add files via upload --- Lsn6AlS.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 Lsn6AlS.c diff --git a/Lsn6AlS.c b/Lsn6AlS.c new file mode 100644 index 0000000..9132a88 --- /dev/null +++ b/Lsn6AlS.c @@ -0,0 +1,155 @@ +#include +#include +#include +#define SIZE 10 +#define binar int +#define SIZE2 100 + +int numS= -1; +binar stack[SIZE2]; +int outBin(binar data) +{ + while (data!=0) + { + if (data%2==0){stack[++numS]=0;} + if (data%2!=0){stack[++numS]=1;} + data/=2; + } +} +void printBin() +{ + for (int i=numS;i>=0;i--) + { + printf("%d",stack[i]); + } +} + +typedef struct +{ + int pr; + int dat; +} Node; + +Node *arr[SIZE]; +int head; +int tail; +int items; + +void init() +{ + for (int i=0;idat=dat; + node->pr=pr; + int flag; + + if (items==0) + { + arr[tail++]=node; + items++; + } + else if (items==SIZE) + { + printf("%s \n","Queue is full"); + return; + } + else + { + int i=0; + int idx=0; + Node*tmp; + for (i=head;ipr>pr) + break; + else + idx++; + } + flag=idx%SIZE; + i++; + while (i<=tail) + { + idx=i%SIZE; + tmp=arr[idx]; + arr[idx]=arr[flag]; + arr[flag]=tmp; + i++; + } + arr[flag]=node; + items++; + tail++; + } +} + +Node* rem() +{ + if (items==0){return NULL;} + else + { + int idx=--tail%SIZE; + Node* tmp=arr[idx]; + arr[idx]=NULL; + items--; + return tmp; + } + +} + +void printq() +{ + printf("["); + for (int i=0;ipr,arr[i]->dat); + printf("]"); + } + +} + + + + +int main() +{ + init(); + ins(2,11); + ins(1,22); + ins(3,33); + ins(5,44); + ins(3,55); + ins(6,66); + ins(3,77); + ins(8,88); + ins(7,99); + ins(5,100); + printq(); + printf("\n"); + for(int i=3;i<6;i++) + { + Node* n= rem(); + } + printq(); + printf("\n"); + ins(6,14); + printq(); + printf("\n"); + outBin(100); + printBin(); + + + + return 0; +} \ No newline at end of file