コード例 #1
0
int main()
{
	enqueue(1);
	enqueue(2);
	enqueue(3);
	enqueue(4);
	printqueue();
	printf("popped element is %d\n",dequeue());
	printf("popped element is %d\n",dequeue());
	printf("popped element is %d\n",dequeue());
	printqueue();
}
コード例 #2
0
ファイル: queuell.c プロジェクト: paramsingh96/Algorithms
int main()
{
	int ch=-1;
	while(ch!=0)
	{
		printf("	==Queue Using Array==\n");
		printf("Exit=0\n");
		printf("Enqueue=1\n");
		printf("Dequeue=2\n");
		printf("Queue Output=3\n");
		printf("Enter your choice: ");
		scanf("%d",&ch);
		
		switch(ch)
		{
			case 0: exit(0);
			case 1: enqueue();
				break;
			case 2: dequeue();
				break;
			case 3: printqueue();
				break;
			default: printf("--Invalid Choice--\n");
		}
	}
	
}
コード例 #3
0
int main()
{
    int data, ch;
    back = NULL;
    front = NULL;

    printf("MENU\nPRINT QUEUE -> 0\nAPPEND      -> 1\nREMOVE      -> 2\nEXIT        -> 3\n");
    printf("\nEnter choice: ");
    scanf("%d", &ch);
    
    do
    {
        switch (ch)
        {
            case 0:
                printqueue();
                break;
                
            case 1:
                printf("Enter data to push: ");
                scanf("%d", &data);
                append(data);
                break;
            
            case 2:
                printf("\nRemoved data: %d\n", rem());
                break;
                
            default:
                printf("Invalid choice");
                break;      
        }
        
        printf("---------------------------------------------------");
        printf("\nMENU\nPRINT QUEUE -> 0\nAPPEND      -> 1\nREMOVE      -> 2\nEXIT        -> 3\n");
        printf("Enter choice: ");
        scanf("%d", &ch);
                
    } while (ch != 3);
    
    return 0;    
}
コード例 #4
0
ファイル: queue.main.c プロジェクト: shrutichapadia/npu
int main(){
  int value =0;
  QueType* queue;
  QueType* q1 = QueType* q2 = NULL;
  printf("enter value; %d\n", value);
  scanf("%d\n",&value);
  queue = CreateQueue();
  while(value <= 7){
    Enqueue(queue,value);
    value++;
    printf("\n Elements in the queue are:\n");
    printqueue(queue,value);
  }

  /* Print all the items */
  while(!IsQueueEmpty(queue)){
    Dequeue(queue,&value);
    printf("%d\n",value);
  }
  DestroyQueue(queue);
  return 0;
}
コード例 #5
0
ファイル: util.c プロジェクト: Hooman3/freebsd
/*
 * Processes a line comparing it with the specified patterns.  Each pattern
 * is looped to be compared along with the full string, saving each and every
 * match, which is necessary to colorize the output and to count the
 * matches.  The matching lines are passed to printline() to display the
 * appropriate output.
 */
static int
procline(struct str *l, int nottext)
{
	regmatch_t matches[MAX_LINE_MATCHES];
	regmatch_t pmatch;
	size_t st = 0;
	unsigned int i;
	int c = 0, m = 0, r = 0;

	/* Loop to process the whole line */
	while (st <= l->len) {
		pmatch.rm_so = st;
		pmatch.rm_eo = l->len;

		/* Loop to compare with all the patterns */
		for (i = 0; i < patterns; i++) {
			if (fg_pattern[i].pattern)
				r = fastexec(&fg_pattern[i],
				    l->dat, 1, &pmatch, eflags);
			else
				r = regexec(&r_pattern[i], l->dat, 1,
				    &pmatch, eflags);
			r = (r == 0) ? 0 : REG_NOMATCH;
			st = (cflags & REG_NOSUB)
				? (size_t)l->len
				: (size_t)pmatch.rm_eo;
			if (r == REG_NOMATCH)
				continue;
			/* Check for full match */
			if (r == 0 && xflag)
				if (pmatch.rm_so != 0 ||
				    (size_t)pmatch.rm_eo != l->len)
					r = REG_NOMATCH;
			/* Check for whole word match */
			if (r == 0 && (wflag || fg_pattern[i].word)) {
				wchar_t wbegin, wend;

				wbegin = wend = L' ';
				if (pmatch.rm_so != 0 &&
				    sscanf(&l->dat[pmatch.rm_so - 1],
				    "%lc", &wbegin) != 1)
					r = REG_NOMATCH;
				else if ((size_t)pmatch.rm_eo !=
				    l->len &&
				    sscanf(&l->dat[pmatch.rm_eo],
				    "%lc", &wend) != 1)
					r = REG_NOMATCH;
				else if (iswword(wbegin) ||
				    iswword(wend))
					r = REG_NOMATCH;
			}
			if (r == 0) {
				if (m == 0)
					c++;
				if (m < MAX_LINE_MATCHES)
					matches[m++] = pmatch;
				/* matches - skip further patterns */
				if ((color == NULL && !oflag) ||
				    qflag || lflag)
					break;
			}
		}

		if (vflag) {
			c = !c;
			break;
		}

		/* One pass if we are not recording matches */
		if (!wflag && ((color == NULL && !oflag) || qflag || lflag || Lflag))
			break;

		if (st == (size_t)pmatch.rm_so)
			break; 	/* No matches */
	}


	/* Count the matches if we have a match limit */
	if (mflag)
		mcount -= c;

	if (c && binbehave == BINFILE_BIN && nottext)
		return (c); /* Binary file */

	/* Dealing with the context */
	if ((tail || c) && !cflag && !qflag && !lflag && !Lflag) {
		if (c) {
			if (!first && !prev && !tail && Aflag)
				printf("--\n");
			tail = Aflag;
			if (Bflag > 0) {
				if (!first && !prev)
					printf("--\n");
				printqueue();
			}
			linesqueued = 0;
			printline(l, ':', matches, m);
		} else {
			printline(l, '-', matches, m);
			tail--;
		}
	}

	if (c) {
		prev = true;
		first = false;
	} else
		prev = false;

	return (c);
}
コード例 #6
0
static int
procline(str_t *l, int nottext)
{
	regmatch_t	pmatch;
	int		c, i, r;
	regoff_t	offset;

	/* size_t will be converted to regoff_t. ssize_t is guaranteed to fit
	 * into regoff_t */
	if (l->len > SSIZE_MAX) {
		errx(2, "Line is too big to process");
	}

	c = 0;
	i = 0;
	if (matchall) {
		c = 1;
		goto print;
	}

	for (i = 0; i < patterns; i++) {
		offset = 0;
redo:
		if (fg_pattern[i].pattern) {
			r = grep_search(&fg_pattern[i], l->dat + offset,
			    l->len - offset, &pmatch);
			pmatch.rm_so += offset;
			pmatch.rm_eo += offset;
		} else {
			pmatch.rm_so = offset;
			pmatch.rm_eo = l->len;
			r = regexec(&r_pattern[i], l->dat, 1, &pmatch, eflags);
		}
		if (r == 0 && xflag) {
			if (pmatch.rm_so != 0 || pmatch.rm_eo != l->len)
				r = REG_NOMATCH;
		}
		if (r == 0) {
			c = 1;
			if (oflag && pmatch.rm_so != pmatch.rm_eo)
				goto print;
			break;
		}
	}
	if (oflag)
		return c;
print:
	if (vflag)
		c = !c;

	if (c && binbehave == BIN_FILE_BIN && nottext)
		return c; /* Binary file */

	if ((tail > 0 || c) && !cflag && !qflag) {
		if (c) {
			if (first > 0 && tail == 0 && (Bflag < linesqueued) &&
			    (Aflag || Bflag))
				printf("--\n");
			first = 1;
			tail = Aflag;
			if (Bflag > 0)
				printqueue();
			linesqueued = 0;
			printline(l, ':', oflag ? &pmatch : NULL);
		} else {
			printline(l, '-', oflag ? &pmatch : NULL);
			tail--;
		}
	}
	if (oflag && !matchall) {
		offset = pmatch.rm_eo;
		goto redo;
	}
	return c;
}