Пример #1
0
Queue_t * queueDoubleResize(Queue_t * queue, bool freeOld) {
    Queue_t * newQueue = queueResize(queue, queue->size * 2);
    if (freeOld) {
        queueDestroy(queue);
    }
    return newQueue;
}
Пример #2
0
queuePtr
queueCreateWithSize (unsigned int numElements, unsigned int elementSize) {
	queuePtr		qPtr;

	//  a queue is made up of two buffers. the first one stores the data
	//  and the 2nd one stores the size of each piece of data.
	
	qPtr = malloc(sizeof(queue));
	if (qPtr != NULL) {
	
		qPtr->dataBuffer = buffCreate(numElements * elementSize);
		qPtr->sizeBuffer = buffCreate(numElements * sizeof(SizeType));
		
		buffReallocAdjustment (qPtr->dataBuffer, numElements * elementSize);
		buffReallocAdjustment (qPtr->sizeBuffer, numElements * sizeof(SizeType));
		
		qPtr->lastDataSize = 0;
		
		qPtr->numPushes = 0;
		qPtr->numPopsLIFO = 0;
		qPtr->numPopsFIFO = 0;

		//  if we cannot allocate both buffer, destroy everything and bail out
		
		if ((qPtr->dataBuffer == NULL) || (qPtr->sizeBuffer == NULL))
			queueDestroy(qPtr);
	}

	return qPtr;
}
Пример #3
0
void serviceConnectionDestroy(ServiceConnection sc)
{
	jausAddressDestroy(sc->address);
	if(sc->serviceConnectionType == SC_EVENT_TYPE) 
	{
		jausMessageDestroy(sc->queryMessage);
	}
	queueDestroy(sc->queue, (void *)jausMessageDestroy);
	free(sc);
}
int main(){

QUEUE  Queue = queueCreate(5);


int i=0,data=2;
for(i=1;i<4;i++){
 
 if(enqueue(Queue,i))
 	printf("enqueue  :%i\n",i);
 //printf("fghfhf %i\n",Queue->s1->index );

}
STACK stack3=queueToStack(Queue);



dequeue(Queue,&data);
printf("dequeue :%i\n",data);//3
//printf("thrth %i\n",Queue->s1->index );
queuePeek(Queue,&data);
printf("Peek :%i\n",data);//4
queuePeek(Queue,&data);
printf("Peek :%i\n",data);//4
queuePeek(Queue,&data);
printf("Peek :%i\n",data);//4
dequeue(Queue,&data);
printf("dequeue :%i\n",data);//3

for(i=5;i<11;i++){
 
 if(enqueue(Queue,i))
 	printf("enqueue  :%i\n",i);
}

queuePeek(Queue,&data);
printf("Peek :%i\n",data);
for(i=5;i<11;i++){
 if(dequeue(Queue,&data))

 	printf("dequeue  :%i\n",data);
}

queueDestroy(Queue);

while(stackPop(stack3,&data)){
	printf("queue to stack elements :%i\n",data);
	
}


}
int main() {
    Queue *queue = malloc(sizeof(Queue));
    queueCreate(queue, 10);
    queuePush(queue, 1);
    queuePush(queue, 2);
    queuePush(queue, 3);
    queuePop(queue);
    queuePop(queue);
    assert(queuePeek(queue) == 3);
    assert(queueEmpty(queue) == 0);
    queueDestroy(queue);

    return 0;
}
int TestQueue()
{
 Queue* Q;
 int i;

 Q = malloc(sizeof(struct Queue));
 
 queueCreate(Q, 10);
 for (i = 0; i < 100; ++i)
   queuePush(Q, i);

 while (!queueEmpty(Q))
 {
 	 printf("%d ", queuePeek(Q));
   queuePop(Q);
 }
  
 printf("\n");

 queueDestroy(Q);
}
Пример #7
0
int
main()
{
    Queue queue;
    queueCreate(&queue, 5);
    queuePush(&queue, 1);
    queuePush(&queue, 2);
    queuePop(&queue);
    printf("%d\n", queuePeek(&queue));

    queuePop(&queue);
    queuePush(&queue, 1);
    queuePush(&queue, 2);
    printf("%d\n", queuePeek(&queue));
    queuePush(&queue, 3);
    printf("%d\n", queuePeek(&queue));
    printf("%d\n", queuePeek(&queue));

    queueDestroy(&queue);
    return 0;
}
int main (int argc, char **argv)
{
	int i;
	int val[] = {2,3,6,8,10,12,14,16,18,20,21,22,23,24,25};
	int value;
	Queue q ;

	queueCreate(&q, 1024);
	for(i = 0; i < 15; i++) {
		queuePush(&q, val[i]);
		print_list(q.node);
	}

	for(i = 0; i < 15; i++) {
		value = queuePeek(&q);
		printf("val = %d\n", value);
		queuePop(&q);
		print_list(q.node);
	}
	queueDestroy(&q);

	return 0;
}
Пример #9
0
void queueFree(QueueClass *queue) {
	queueDestroy(queue);
	free(queue);
}
Пример #10
0
void stackDestroy (struct node **n){
	 queueDestroy (n); //destroy stack that used queue
}
Пример #11
0
void serviceConnectionDestroyNoMutex(ServiceConnection sc)
{
	jausAddressDestroy(sc->address);
	queueDestroy(sc->queue, (void *)jausMessageDestroy);
	free(sc);
}
Пример #12
0
struct Stack* parseCmdLine(const char* const clStr)
{
	struct CmdLine* cmdLine;
	struct Queue* tokens;
	char *token, *nextToken, *command;
	char **operators, **files;
	bool background, pushed, pipedIn, pipeOut;
	struct Stack* commandStack;
	int i;
	struct LinkedList* parameters;

	tokens=tokenize(clStr);
	commandStack=stackCreate();

	pipedIn=false;
	pipeOut=false;

	while (!queueIsEmpty(tokens))
	{
		//Get Command
		pushed=false;
		command=(char *)queueGetFront(tokens);

		//Parse Parameters
		parameters=listCreate();
		if (!queueIsEmpty(tokens))
		{
			while (!queueIsEmpty(tokens))
			{
				token=(char *)queuePeek(tokens);
				if (!isDelimiter(token))
				{
					listAppend(parameters, token);
					queueGetFront(tokens);
				}
				else
				{
					break;
				}
			}
		}

		//Check for Redirects
		operators=(char **)malloc(sizeof(char*)*REDIRECTS);
		files=(char **)malloc(sizeof(char*)*REDIRECTS);
		for (i=0; i<REDIRECTS; i++)
		{
			operators[i]=NULL;
			files[i]=NULL;
		}
		if (!queueIsEmpty(tokens))
		{
			for (i=0; i<REDIRECTS && !queueIsEmpty(tokens); i++)
			{
				token=(char *)queuePeek(tokens);

				if (strcmp(token, CL_TOKEN_GREATER_THAN)==0
                                    || strcmp(token, CL_TOKEN_LESS_THAN)==0)
				{
					operators[i]=token;
					queueGetFront(tokens);
					token=(char *)queueGetFront(tokens);
					files[i]=token;
				}
				else
				{
					break;
				}
			}
		}

		//Check for background process or pipe
		background=false;
		pipeOut=false;
		if (!queueIsEmpty(tokens))
		{
			token=(char *)queuePeek(tokens);
			if (strcmp(token, CL_TOKEN_AMP)==0)
			{
				queueGetFront(tokens);
				background=true;
			}
			else if (strcmp(token, CL_TOKEN_PIPE)==0)
                        {
				queueGetFront(tokens);
                                pipeOut=true;
                        }
		}
		
		//Add Command to Stack of Commands
		pushCmdLine(commandStack, command, parameters, operators, files, pipedIn, pipeOut, background);
		pushed=true;
		pipedIn=pipeOut;

		if (background || !pipeOut)
		{
			break; //Terminated because in background or syntax error
		}
	}

	if (!pushed)
	{
		free(operators);
		free(files);
	}
	
        queueDestroy(tokens, false);

	return commandStack;
}