Блог пользователя ShauryaH4X

Автор ShauryaH4X, история, 11 дней назад, По-английски
#include<stdio.h>
#include<stdlib.h>

typedef int itype;

typedef struct Cq{
    int size,count,front,rear;
    itype *a;
}Cq;

void initialize(Cq * ref,int n) {
    ref->count=0;
    ref->size=n;
    ref->front=0;
    ref->rear=-1;
    ref->a=(int *)malloc(n*sizeof(int));
    if(ref->a==NULL) {
        printf("Memory not allocated");
        exit(1);
    }
    printf("1");
}

char isfull(Cq *ref) {
    return ref->count==ref->size;
}

char isempty(Cq *ref) {
    return ref->count==0;
}

void insert(Cq *ref,itype x) {
    if(isfull(ref)) {
        printf("Queue full");
        exit(2);
    }
    ref->rear=(ref->rear+1)%(ref->size);
    ref->a[ref->rear]=x;
    ref->count=ref->count+1;
    printf("2");
}
int size(Cq *ref) {
    return ref->count;
}

int main() {
    Cq a;
    initialize(&a,5);
    insert(&a,10);
    insert(&a,20);
    insert(&a,30);
    insert(&a,40);
    return 0;
}

I was asked to make circular queue with count in my proficiency test today but it was giving me error. Can you help me find out error in this code.

Program 'Cq.exe' failed to run: Insufficient system resources exist to complete the requested serviceAt line:1 char:84
+ ... rogramming\codechef\" ; if ($$$?) { gcc Cq.c -o Cq } ; if ($$$?) { .\Cq }
+                                                                    ~~~~.
At line:1 char:84
+ ... rogramming\codechef\" ; if ($$$?) { gcc Cq.c -o Cq } ; if ($$$?) { .\Cq }
+                                                                    ~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

Looks like segmentation fault but where

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится