예제 #1
0
int main(void)
{
	char buf[1024] = "";
	char *p = NULL;
	fgets(buf,sizeof(buf),stdin);
	p = strtok(buf," \n");
	push2(atoi(p));
	while((p = strtok(NULL, " \n")) != NULL)
	{
		char op;
		int b, a;
		switch(*p)
		{
			case '+':
			case '-':
					//if(!is_empty())
					{
						while (top1 != 0) {
							op = pop1();
							//if(*op == ' ')
							//	break;
						b = pop2(); 
						a = pop2(); 
							if(op == '+')
						push2(a + b);
						else 
						push2(a - b);
						};
					}
						push1(*p);
						break;
	 		case '*':
			case '/':
						push1(*p);
						break;
			default: push2(atoi(p));
		}
	}
 switch(pop1()){
	 case '+': printf("%d\n",pop2() + pop2());break;
	 case '-': printf("%d\n",pop2() - pop2());break;
	 case '*': printf("%d\n",pop2() * pop2());break;
	 case '/': printf("%d\n",pop2() / pop2());break;
 }
	//printf("%d\n",pop2());
	destory();
	return 0;
}
예제 #2
0
파일: que_w_stk.c 프로젝트: n0x3u5/Code
int main()
{
	int choice, item;
	do
	{
		printf("Press\n[1] To insert\n[2] To delete\n[3] To display\n[4] To exit\nEnter choice: ");
		scanf("%d",&choice);
		switch(choice)
		{
			case 1:
				printf("Enter the number to insert: ");
				scanf("%d",&item);
				push1(item);
				pop1();
				break;
			case 2:
				pop2();
				break;
			case 3:
				printf("The content of queue is: \n");
				display();
				break;
			case 4:
				exit(0);
			default:
				printf("Invalid Entry!");
		}
	}while(1);
}
예제 #3
0
파일: expression.cpp 프로젝트: WLBF/OJ
int result(char fir[],int plus) //算出结果 
{
    char c,ch;
    int x,y,i = 0;
    count1 = 0;
    count2 = 0;
    push2('#');
    while( fir[i]!='#' || optr[count2-1]!='#')
    {
        c = fir[i];
        if( isdigit(c) )
        {
            push1(c-'0');
            i++;
            continue;
        }
        if( isalpha(c) )
        {
            push1(c-'a'+plus);
            i++;
            continue;
        }
        if(c == '+' || c== '-'||c=='*' || c=='('||c==')'||c=='#')
        {
            switch( record(optr[count2-1],c) )
            {
                
                case -1: push2(c); i++; break;
                case 0 : pop2(); i++; break;
                case 1 : ch = pop2();
                         y = pop1();
                         x = pop1(); 
                         push1(computer(x,y,ch));
                         break;
            }
        }
        else
            i++;
    }
return opnd[count1-1];
}
예제 #4
0
/* Driver program to test twStacks class */
int main()
{
  struct TwoStack * twoStacks = createStacks(5);
  push1(twoStacks, 5);
  push2(twoStacks, 10);
  push2(twoStacks, 15);
  push1(twoStacks, 11);
  push2(twoStacks, 7);
  printf("Popped element from stack1 is %d", pop1(twoStacks));
  push2(twoStacks, 40);
  printf("\nPopped element from stack2 is %d", pop2(twoStacks));
  return 0;
}
예제 #5
0
int main(){
	struct doublestack dstack;
	dstack.topFirstStack =-1;
	dstack.topSecondStack =100;
	push1(&dstack,10);
	push1(&dstack,20);
	push2(&dstack,30);
	push2(&dstack,50);
	int x = pop1(&dstack);
	printf("Pop item from stack one %d \n",x);
		int y = pop2(&dstack);
		printf("Pop item from stack two %d \n",y);
}
예제 #6
0
int main()
{
	size = 5;
	top1= -1;
	top2 = 5;
	push1(5);
	push2(10);
	push1(45);
	push1(12);
	push2(41);
	printf("Element Popped from stack 1 is: %d\n",pop1());				
	printf("Element Popped from stack 2 is: %d\n",pop2());
	return 0;
}
예제 #7
0
void dequeue()
{
    int i;
 
    for (i = 0;i <= count;i++)
    {
        push2(pop1());
    }
    pop2();
    count--;
    for (i = 0;i <= count;i++)
    {
        push1(pop2());
    }
}
예제 #8
0
TEST(v_init, v_init)
{
	auto v_rest = [](size_t i) { return -80.0f + i * 2.0f;};

	auto run = [v_rest](const std::string &sim) {
		std::cout << "v_init integration test running on " << sim << std::endl;
		Network net;
		net.logger().min_level(LogSeverity::DEBUG);
		Population<IfCondExp> pop1(net, 10);
		Population<IfCondExp> pop2(net, 5);
		pop1.signals().record_v();
		pop2.signals().record_v();
		for (size_t i = 0; i < pop1.size(); i++) {
			pop1[i].parameters().v_rest(v_rest(i));
		}
		pop2.parameters().v_rest(-77.0);
		net.run(sim, 1000.0);

		for (size_t i = 0; i < pop1.size(); i++) {
			const auto &data = pop1[i].signals().get_v();
			for (size_t j = 0; j < 1; j++) {
				EXPECT_NEAR(v_rest(i), data(j, 1), 1.0f);
			}
		}
		for (size_t i = 0; i < pop2.size(); i++) {
			const auto &data = pop2[i].signals().get_v();
			for (size_t j = 0; j < 1; j++) {
				EXPECT_NEAR(-77.0, data(j, 1), 1.0f);
			}
		}
	};

	// Run on all available PyNN platforms
	for (const std::string &sim: PyNN::simulators()) {
		run("pynn." + sim);
	}

	// Run on the native NEST backend if available
	if (NEST::installed()) {
		run("nest");
	}
}
예제 #9
0
int main()
{
  int choice, num, exit = 0;
  while(exit != 1){
    printf("1. Input to stack-1\n"
	   "2. Input to stack-2\n"
	   "3. POP from stack-1\n"
	   "4. POO from stack-2\n"
	   "5. Print Stacks\n"
	   "6. Exit\n");
    scanf("%d", &choice);
    switch(choice){
    case 1:
      printf("Input a number to add to the stack\n");
      scanf("%d", &num);
      push1(num);
      break;
    case 2:
      printf("Input a number to add to the stack\n");
      scanf("%d", &num);
      push2(num);
      break;
    case 3:
      pop1();
      break;
    case 4:
      pop2();
      break;
    case 5:
      print();
      break;
    case 6:
      exit = 1;
      break;
    default:
      printf("Not a valid choice, Try Again!!\n");
      break;
    }
  }
}
예제 #10
0
파일: myshell.c 프로젝트: sagar55/MyProg
int main()
{
	char c[200],a[200],temp[50],home[50],*args[50];
stk S;
pid_t p;
int j,i,fd,n,flag=0,pid,num_arg,status,block;
  sigset(SIGCHLD, sig_handler);
ini(&S);
getCurrentDirectory(home);
while(1) {
if(!flag){
getCurrentDirectory(temp);
printf("myshell[%s]:- ", temp);
gets(a);
num_arg = parse_cmd(a,args);}
flag=0;

	if(a[0]== '\0');
else if(feof(stdin))
{printf("\n");
exit(0);}
else if(num_arg>1&&strstr(args[1],"&")){
        pid = fork();
if(pid==0)
{signal(SIGALRM,times_up);  alarm (10);
execvp(args[0], args);
//execlp(arg[0], "/usr", (char *) 0);
while(1);
            exit(0); }

           else{
    printf("Waiting for child, pid = %d\n",pid);
    waitpid(pid, &status, 0);
    printf("child process finished of pid = %d\n",pid);
  }
} 
else if(!strcmp(a,"ls")){
j=strlen(a);
push(a,&S,j);
system("ls");
}
else if(!strcmp(args[0],"history"))
{
i=0;n=0;
if(num_arg==1)
pop(&S);
else{
strcpy(c,args[1]);
while(c[i]!='\0')
{  n=n*10+c[i++]-48;}
pop1(&S,n);}
j=strlen(a);push(a,&S,j);
}
else if(!strcmp(args[0],"issue"))
{
n=0;push(a,&S,j);strcpy(c,args[1]);
while(c[i]!='\0')
{  n=n*10+c[i++]-48;}
j=strlen(a);
strcpy(a,S.a[n-1]);
flag=1;
}
else if(!strcmp(args[0],"cd"))
{j=strlen(a);push(a,&S,j);
if(num_arg==1)
changeDirectory1(home);
else{
changeDirectory(args[1]);
}}
else if (!strcmp(args[0],"rm")){
	 push(a,&S,j);
	fd=unlink(args[1]);
	printf("File deleted\n");
	if(fd==-1)
	printf("Can't delete file\n");
}
else if(!strcmp(a,"quit"))
exit(0);
else 
printf("not a recognized command\n");
	}
	printf("\n");
	return 0;
}
예제 #11
0
double eval(stack * stk, stack1 * no)
{

        stack1 nos = NULL;
        double x, y, z;
        char ch;
        ldiv_t ldivt;
        while (!empty(*stk)) {
                *stk = pop(*stk, &ch);
                if (ch == 'N') {
                        *no = pop1(*no, &x);
                        nos = push1(nos, x);
                } else if (ch == (char)0xD8) {
                } else {
                        nos = pop1(nos, &y);
                        if ((ch >= (char)0xA2 && ch <= (char)0xCA) && ch != (char)0xAA && ch != (char)0xCB
                            && ch != (char)0xB9)
                                x = 0;
                        else
                                nos = pop1(nos, &x);

                        switch (ch) {
                        case '+':
                                z = add(x, y);
                                break;
                        case '-':
                                z = dif(x, y);
                                break;
                        case '*':
                                z = mul(x, y);
                                break;

                        case '/':
                                if (y == 0.0) {
                                        eqp_errno = 6;
                                        return (0);
                                }
                                z = divide(x, y);
                                break;
                        case '^':
                                z = pow(x, y);
                                break;
                        case '%':
                                z = mod(x, y);
                                break;

                                /* The inline comments give the equivalent 
                                 * gnuplot function 
                                 */
                        case (char)0xA2:      /* abs(x) */
                                z = fabs(y);
                                break;
                        case (char)0xA3:      /* acos(x) */
                                if (y > 1 || y < -1) {
                                        /*
                                           eqp_errno = 9 ;
                                           return(0);
                                         */
                                }
                                z = acos(y);
                                break;
                        case (char)0xA4:      /* acosh(x) */
                                z = acosh(y);
                                break;
                        case (char)0xA6:      /* asin(x) */
                                if (y > 1 || y < -1) {
                                        /*
                                           eqp_errno = 10 ;
                                           return(0);
                                         */
                                }
                                z = asin(y);
                                break;
                        case (char)0xA7:      /* asinh(x) */
                                z = asinh(y);
                                break;
                        case (char)0xA8:      /* atan(x) */
                                z = atan(y);
                                break;
                        case (char)0xA9:      /* atanh(x) */
                                if (y > 1 || y < -1) {
                                        eqp_errno = 11;
                                        return (0);
                                }
                                z = atanh(y);
                                break;
                        case (char)0xAA:      /* atan2(y,x) */
                                z = atan2(x, y);
                                break;
                        case (char)0xAB:      /* besj0(x) */
                                z = j0(y);
                                break;
                        case (char)0xAC:      /* besj1(x) */
                                z = j1(y);
                                break;
                        case (char)0xAD:      /* besy0(x) */
                                if (y <= 0) {
                                        eqp_errno = 8;
                                        return (0);
                                }
                                z = y0(y);
                                break;
                        case (char)0xAE:      /* besy1(x) */
                                if (y <= 0) {
                                        eqp_errno = 18;
                                        return (0);
                                }
                                z = y1(y);
                                break;
                        case (char)0xAF:      /* ceil(x) */
                                z = ceil(y);
                                break;
                        case (char)0xB1:      /* cos(x) */
                                z = cos(y);
                                break;
                        case (char)0xB2:      /* cosh(x) */
                                z = cosh(y);
                                break;
                        case (char)0xCB:      /* div(num,denom) */
                                ldivt = ldiv((int) x, (int) y);
                                z = (double) ldivt.quot;
                                break;
                        case (char)0xB3:      /* erf(x) */
                                z = erf(y);
                                break;
                        case (char)0xB4:      /* erfc(x) */
                                z = erfc(y);
                                break;
                        case (char)0xB5:      /* exp(x) */
                                z = exp(y);
                                break;
                        case (char)0xB6:      /* floor(x) */
                                z = floor(y);
                                break;
                        case (char)0xB7:      /* gamma(x) */
                                z = exp(lgamma(y));
                                break;
                        case (char)0xBB:      /* int(x) */
                                z = rint(y);
                                if (z > 0 && z > y)
                                        z--;
                                if (z < 0 && z < y)
                                        z++;
                                break;
                        case (char)0xBC:      /* inverf(x) */
                                if (y <= -1 || y >= 1) {
                                        eqp_errno = 19;
                                        return (0);
                                }
                                z = inverf(y);
                                break;
                        case (char)0xBD:      /* invnorm(x) */
                                if (y <= 0 || y >= 1) {
                                        eqp_errno = 16;
                                        return (0);
                                }
                                z = sqrt(2) * inverf(2 * y - 1);
                                break;
                        case (char)0xBE:      /* lgamma(x) */
                                z = lgamma(y);
                                break;
                        case (char)0xBF:      /* log(x) */
                                if (y <= 0) {
                                        eqp_errno = 21;
                                        return (0);
                                }
                                z = log(y);
                                break;
                        case (char)0xC0:      /* log10(x) */
                                z = log10(y);
                                if (y <= 0) {
                                        eqp_errno = 20;
                                        return (0);
                                }
                                break;
                        case (char)0xC1:      /* norm(x) */
                                z = .5 * (1 + erf(y / sqrt(2)));
                                break;
                        case (char)0xC2:      /* rand(x) */
                                z = ((double) rand()) / RAND_MAX;
                                break;
                        case (char)0xC4:      /* sgn(x) */
                                if (y > 0)
                                        z = 1;
                                else if (y < 0)
                                        z = -1;
                                else
                                        z = 0;
                                break;
                        case (char)0xC5:      /* sin(x) */
                                z = sin(y);
                                break;
                        case (char)0xC6:      /* sinh(x) */
                                z = sinh(y);
                                break;
                        case (char)0xC7:      /* sqrt(x) */
                                z = sqrt(y);
                                break;
                        case (char)0xC8:      /* tan(x) */
                                z = tan(y);
                                break;
                        case (char)0xC9:      /* tanh(x) */
                                z = tanh(y);
                                break;
                        }
                        nos = push1(nos, z);
                }
        }
        nos = pop1(nos, &z);
#ifdef DEBUG
        printf("\n%lf", z);
#endif
        return (z);
}
예제 #12
0
파일: rules1.c 프로젝트: kvv1/kvvmaps
static int eval1(uint8_t a, uint8_t len) {
	err = ERR_OK;

	int tos = 0;

	sp = stack + STACK_SIZE;

	uint8_t a1 = a + len;

	while (a < a1) {
		uint8_t c = get(a++);

		uint8_t bcGroup = c & (~(MAX_QUICK - 1));

		if (bcGroup == LIT_MASK) {
			int n = c & (MAX_QUICK - 1);
			push1(tos);
			tos = n - MAX_QUICK / 2;
		} else if (bcGroup == REG_MASK) {
			int n = c & (MAX_QUICK - 1);
			int val = 0;
			char b = getReg(n, &val);
			if (!b)
				err = ERR_WRONG_REGISTER;
			push1(tos);
			tos = val;
		} else {
			switch (c) {
			case LIT: {
				int s = get16(a);
				a += 2;
				push1(tos);
				tos = s;
				break;
			}
			case REG: {
				int s = get16(a);
				a += 2;
				int val = 0;
				char b = getReg(s, &val);
				if (!b)
					err = ERR_WRONG_REGISTER;
				push1(tos);
				tos = val;
				break;
			}
			case COND: {
				uint8_t n = get(a++);
				int n1 = tos;
				tos = pop1();
				if (!n1)
					a += n;
				break;
			}
			case COND1: {
				uint8_t n = get(a++);
				a += n + 1;
				break;
			}
			case EQ:
				tos = tos == pop1();
				break;
			case NEQ:
				tos = tos != pop1();
				break;
			case LT:
				tos = pop1() < tos;
				break;
			case LE:
				tos = pop1() <= tos;
				break;
			case GT:
				tos = pop1() > tos;
				break;
			case GE:
				tos = pop1() >= tos;
				break;
			case PLUS:
				tos = pop1() + tos;
				break;
			case MINUS:
				tos = pop1() - tos;
				break;
			case MUL:
				tos = pop1() * tos;
				break;
			case DIV:
				tos = pop1() / tos;
				break;
			case NOT:
				tos = !tos;
				break;
			case NEG:
				tos = -tos;
				break;
			case OR: {
				uint8_t n = get(a++);
				tos = tos != 0;
				if (tos)
					a += n;
				else
					tos = pop1();
				break;
			}
			case AND: {
				uint8_t n = get(a++);
				if (!tos)
					a += n;
				else
					tos = pop1();
				break;
			}
			case NE0:
				tos = tos != 0;
				break;
			case PAR:
				break;
			default:
				err = ERR_UNKNOWN_BYTECODE;
				return 0;
			}
		}
		if (err != ERR_OK)
			return 0;
	}

	int n = tos;
	tos = pop1();

	if (err != ERR_OK)
		return 0;

	if (sp != stack + STACK_SIZE)
		err = ERR_STACK_BALANCE;

	return n;
}
예제 #13
0
파일: tu.cpp 프로젝트: xtaq/profile
int main(){
    int m , n ;
    int v1 , v2;
    int i;
    int count = 0;
    int mark;
    node *p;
    scanf ("%d%d",&n,&m);
    for(  i = 1; i <= m ; i ++)
    {
        scanf("%d%d",&v1,&v2);
        add(v1,v2);
    }
    for( i = 1; i<= n ; i ++)
    {
    	if(root[i].in == 0)
	{
		push(i);
		root[i].in = -1;
	}
    }
   /* for( i = 1; i <= n ;i ++)
    {
    	printf("\n%d",i);
	p = root[i].next;
	while(p)
	{
		printf("->%d",p->num);
		p = p->next;
	}
    }*/
    while(!empty())
    {
    	count++;
	while(!empty())
	{
		mark = pop();
		if( root[mark].next)
		{
			p = root[mark].next;
			root[p->num].in--;
			if(root[p->num].in == 0)
			{
				push1(p->num);
			}
			p = p->next;
		}
		while(p)
		{
			root[p->num].in--;
			if(root[p->num].in == 0)
			push1(p->num);
			p = p->next;
		}
	}
	/*for(i = 1; i <= n ; i ++)
	{
		if(root[i].in == 0)
		{
			push(i);
			root[i].in = -1;
		}
	}*/
	if(empty1())
	break;
	while(!empty1())
	{
		push(pop1());
	}
		
     }
     printf("%d",count );

/*
	
    for( i = 1 ; i <= n ;i ++)
    {
        printf("%d %d %d\n",i,root[i].in,root[i].out);
    }
    */
    return 0;
}
int main()
{
	int i,j,k,pos,xtmp,ytmp,source,sink,curVer;
	FILE *fin  = fopen ("project1.in", "r");
	fscanf(fin,"%d %d",&verSum,&edgSum);

	for(i=0;i<verSum;i++)
	{
		fscanf(fin,"%d %d %d",&pos,&xtmp,&ytmp);
		vertices[pos].pos=(xtmp<<16)|ytmp;
		vertices[pos].is=1;
	}

	for(i=0;i<edgSum;i++)
	{
		fscanf(fin,"%d %d",&tmp[i].pos1,&tmp[i].pos2);
		vertices[tmp[i].pos1].limit++;
		vertices[tmp[i].pos2].limit++;
	}
	i=start();

	vertices[i].suffix=0;
	for(k=1;k<verSum;k++)
	{
		j=next(i);
		vertices[j].suffix=vertices[i].suffix+vertices[i].limit;
		vertices[i].limit=vertices[i].suffix;
		i=j;
	}
	vertices[i].limit=vertices[i].suffix;
	for(i=0;i<edgSum;i++)
	{
		edges[vertices[tmp[i].pos1].limit++]=tmp[i].pos2;
		edges[vertices[tmp[i].pos2].limit++]=tmp[i].pos1;
	}
	while(1)
	{
		printf("input two place:");
		scanf("%d %d",&source,&sink);
		visit[source]=reach[source]=1;
		heapsize=0;
		push1(source);
		push2(source);
		cost[source]=0;
		curVer=source;
		while(curVer!=sink)
		{
			for(i=vertices[curVer].suffix;i<vertices[curVer].limit;i++)
			{
				if(visit[edges[i]])
					continue;
				if(reach[edges[i]]==0)
				{
					cost[edges[i]]=cost[curVer]+distance(vertices[curVer].pos,vertices[edges[i]].pos);
					reach[edges[i]]=1;
					push2(edges[i]);
					Insert(edges[i]);
					prefix[edges[i]]=curVer;
				}
				else if(cost[edges[i]]>cost[curVer]+distance(vertices[curVer].pos,vertices[edges[i]].pos))
				{
					cost[edges[i]]=cost[curVer]+distance(vertices[curVer].pos,vertices[edges[i]].pos);
					Update(edges[i]);
					prefix[edges[i]]=curVer;
				}
			}
			if(heapsize==0)
			{
				break;
			}
			curVer=HeapMin();
			visit[curVer]=1;
			push1(curVer);
		}
		while(Empty1())
		{
			pop1();
		}
		while(Empty2())
		{
			pop2();
		}
		if(curVer==sink)
		{
			printf("distance:%lf\n",cost[sink]);
			while(curVer!=source)
			{
				push(curVer);
				curVer=prefix[curVer];
			}
			push(source);
			printf("route:");
			while(Empty())
			{
				pop();
			}
			printf("\n");
		}
		else
		{
			printf("NULL\n");
		}
	}
	return 0;
}