示例#1
0
void rule2(int *board, int i, int j,int h,int w)
{
    /*Una célula viva con 2 ó 3 células vecinas vivas sigue viva, en otro caso muere o
    permanece muerta (por "soledad" o "superpoblación").*/


    int neighbors;
    status *s;
    s=(status*)malloc(sizeof(status));
    if(board[i*w+j]==LIVE)
    {
        neighbors=checkNeighbors(board,i,j,h,w);

        if(neighbors==2 || neighbors==3)
        {
            s->i=i;
            s->j=j;
            s->status=LIVE;
            insertBegin(&statusList,s);
        }
        else
        {
            s->i=i;
            s->j=j;
            s->status=DEAD;
            insertBegin(&statusList,s);
        }
    }
}
示例#2
0
void Objects::insertModel(const MWWorld::Ptr &ptr, const std::string &mesh, bool animated, bool allowLight)
{
    insertBegin(ptr);

    std::auto_ptr<ObjectAnimation> anim (new ObjectAnimation(ptr, mesh, mResourceSystem, animated, allowLight));

    mObjects.insert(std::make_pair(ptr, anim.release()));
}
示例#3
0
void Objects::insertNPC(const MWWorld::Ptr &ptr)
{
    insertBegin(ptr);
    ptr.getRefData().getBaseNode()->setNodeMask(Mask_Actor);

    std::auto_ptr<NpcAnimation> anim (new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), mResourceSystem));

    mObjects.insert(std::make_pair(ptr, anim.release()));
}
示例#4
0
int main()
{
	int d  , o , i , q = 1 ;
	struct Clist *head = NULL ;

	while(q){
		printf("Enter 1 to insert at the begining\nEnter 2 to insert at the end\nEnter 3 to delete at the begining\nEnter 4 to delete at the end\nEnter 5 to print the list\nEnter 6 to exit");
		scanf("%d" , &o) ;

		switch(o)
		{
			case 1 :
			{
				printf("Enter the data : ");
				scanf("%d" , &d) ;
				insertBegin(&head , d) ;
				break ;
			}

			case 2 :
			{
				printf("Enter the data : ");
				scanf("%d" , &d) ;
				insertEnd(&head , d) ;
				break ;
			}

			case 3 :
			{
				deleteStart(&head) ;
				break ;
			}

			case 4 :
			{
				deleteEnd(&head) ;
				break ;
			}

			case 5 :
			{
				display(head) ;
				break ;
			}
		    
		    case 6 :
		    {
		    	q = 0 ;
		    }
		}	
	}

}
示例#5
0
void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, bool weaponsShields)
{
    insertBegin(ptr);
    ptr.getRefData().getBaseNode()->setNodeMask(Mask_Actor);

    // CreatureAnimation
    std::auto_ptr<Animation> anim;

    if (weaponsShields)
        anim.reset(new CreatureWeaponAnimation(ptr, mesh, mResourceSystem));
    else
        anim.reset(new CreatureAnimation(ptr, mesh, mResourceSystem));

    mObjects.insert(std::make_pair(ptr, anim.release()));
}
示例#6
0
文件: objects.cpp 项目: ace13/openmw
void Objects::insertModel(const MWWorld::Ptr &ptr, const std::string &mesh, bool animated, bool allowLight)
{
    insertBegin(ptr);

    std::auto_ptr<ObjectAnimation> anim (new ObjectAnimation(ptr, mesh, mResourceSystem, animated, allowLight));

    if (!allowLight)
    {
        RemoveParticlesVisitor visitor;
        anim->getObjectRoot()->accept(visitor);
        visitor.remove();
    }

    mObjects.insert(std::make_pair(ptr, anim.release()));
}
示例#7
0
文件: 1.c 项目: theja0473/C-Programs
	int main()
	{
		int option, choice, x,v;


		printf("1. Insert.\n");
		printf("2. Delete.\n");
		printf("3. Display.\n");
		printf("4. Exit...\n");
		printf("Enter the option : ");
		scanf("%d", &option);

		switch(option)
		{

			case 1:
				printf("1. Insert Begin. \n");
				printf("2. Insert Mid.\n");
				printf("3. Insert End.\n");

				printf("Enter the option : ");
				scanf("%d", &choice);

				switch(choice)
				{	
					case 1:
						printf("Enter the data to be inserted in the begining... : ");
	scanf("%d", &x);
						insertBegin(x);
						break;

					case 2:
						printf("enter the data to be inserted in the middle... :");
	scanf("%d", &x);
						insertMidAfter(v,x);
						break;
					
					


				}

		Create();
		}

		return 0;
	}
示例#8
0
void rule1(int *board, int i, int j,int h,int w)
{
    //Una célula muerta con exactamente 3 células vecinas vivas "nace" (al turno siguiente estará viva).
    int neighbors;
    status *s;
    s=(status*)malloc(sizeof(status));
    if(board[i*w+j]==DEAD)
    {
        neighbors=checkNeighbors(board,i,j,h,w);

        if(neighbors==3)
        {
            s->i=i;
            s->j=j;
            s->status=LIVE;
            insertBegin(&statusList,s);

        }
    }


}
示例#9
0
void CircleList< TYPENODE >::insertSort( Node<TYPENODE> node ){
    if ( isEmpty( ) ){
        head = new Node< TYPENODE >( node );
        head->next = head;
    }
    else if ( head->next->info.getPlaque( ).compare( node.info.getPlaque( ) ) > 0 ){
        insertBegin( node );
    }
    else if ( head->info.getPlaque( ).compare( node.info.getPlaque( ) ) < 0 ){
        insertLast( node );
    }
    else{
        Node< TYPENODE > *newNode = new Node< TYPENODE >( node );
        Node< TYPENODE > *actNode = head->next;
        Node< TYPENODE > *antNode = head;
        while( node.info.getPlaque( ).compare( actNode->info.getPlaque() ) > 0  ){
            antNode = actNode;
            actNode = actNode->next;
        }
        antNode->next = newNode;
        newNode->next = actNode;
    }
}
示例#10
0
文件: main.c 项目: sbaychev/C
int main()
{
LIST *pFirst = NULL, *p;
int res, i, mode, c, t;
double average = 0;
FILE *pOut = NULL, *pIn = NULL;
char Fname[]="Car_List_bin.dat";
BODY car;
char carIDnum [MIN_LENGTH+1], carBran [MAX_LENGTH+1];
char *menu[] = {"USED CAR DEALERSHIP CATALOGUE\n\tSUPPORT DATA MENU",
"1-Enter data for a new car",
"2-Write the data into a binary file",
"3-Read the data from a binary file",
"4-Display all available cars",
"5-Delete a car by a car identification number",
"6-Search and Display available cars by a specified brand",
"7-Display all cars from a speciffic brand that have a price\nlarger than the average for the brand",
"8-Destroy the car data and Exit"};

do
{ system("cls");
for(i=0; i < 9; i++)
printf("\n%s\n",menu[i]);
do
{ 
fflush(stdin);
printf ("\n\nChoose mode[1-8]: ");
res = scanf("%d", &mode);
}while(res !=1);
	switch(mode)
	{
		case 1: //data entry from the keyboard
		for(i = 0; i < LOOPS; i++)
		{
			res = enterBody(&car);
			if (res != 1 ) //the function returns 0 or 1
			{
			printf("\nError in initialization %d!\n", res);
			break;
			}
			p = insertBegin(pFirst, car);
			if(p == NULL)
			{
			printf("\n\nNot enough memory!\n");
			break;
			}
			pFirst = p;
		}
		system("pause");
		break;
		case 2: // openning the file and writing on it the list
		{				
			if (pFirst == NULL)
			{	printf("\nThe CAR CATALOGUE is Empty, there are no car records to be saved!\n");system("pause");break;}
			pOut = fopen(Fname, "wb");
			if(pOut == NULL)
			{ printf("\nCan't open file for writing!\n");
			  break;
			}
			for(p = pFirst; p != NULL ; p = p->pNext)
			{
				res = writeEl(p, pOut);
				if(res != 1)
				{   
					printf("\nWriting error %d !\n\n", res);
					break;
				}
			}
			fclose(pOut);
			removeList(&pFirst);
			printf("\nThe Catalogue data has been recorded on the Car_List_bin.dat file\n");
		}
		system("pause");
		break;
		case 3: // openning the file and reading the list
		{
		pIn = fopen(Fname, "rb");
		if( pIn == NULL)
		{
			printf("\nCan't open file for reading!\n");
			break;
		}
			do
			{
				res = readEl(&car, pIn);
				if (res != 1 && res != -4 )
				{
				printf("\nReading error %d !\n", res);
				break;
				}
				if (res != -4)
				{   p = insertBegin(pFirst, car);
					if ( p == NULL )
					{ printf("\nNot enough memory!\n");
					  break;
					}
				pFirst = p;
				}
			}while(res == 1);
		fclose(pIn);
		printf("\nThe file has been read and the catalogue is available for Display via Option 4.\n");
		}
		system("pause");
		break;
		case 4: // Displaying all available cars on the screen
		if (pFirst!=NULL)
		{
			printf("\nCarID:     Color:               EngineSize: Brand:               Price:\n");
			print(pFirst);
		}
		else
			printf("\nThe CAR CATALOGUE is Empty, there are no cars to be Displayed!\n");
		system("pause");
		break;
		case 5:
			if (pFirst == NULL)
			{	printf("\nThe CAR CATALOGUE is Empty, there are no cars to be deleted!!\n");system("pause");break;}
			do{
				fflush(stdin);
				printf("\nDelete a car by entering carID|It's an alphameric sequence of upto 10 symbols|: "); 
				if(gets(carIDnum) == NULL)//the Ctrl/Z combination
				{
					printf("Error in initialization!\n");
					break;
				}
				if(carIDnum[0] == '\0')//if nothing has been entered
				{
					printf("\nError, nothing has been entered, try again!\n");
					break;
				}
				else
				{
					delByCarID(&pFirst, carIDnum);
				}

			 }while( strlen(carIDnum) != MIN_LENGTH );
		system("pause");
		break;
		case 6: 
		if (pFirst == NULL)
		{	printf("\nThe CAR CATALOGUE is Empty, there are no cars to be searched/ displayed!\n");system("pause");break;}
		do{
			fflush(stdin);
			printf("\nSearch and Display all cars by a specified by you car brand |Character set of up to 20 symbols|: "); 
			if(gets(carBran) == NULL)//the Ctrl/Z combination
			{
				printf("\nError in initialization!\n");
				break;
			}
			if(carBran[0] == '\0')//if nothing has been entered
			{
				printf("\nError, nothing has been entered, try again!\n");
				break;
			}
			else
			{
				displByBrand(carBran, &pFirst);
			}
		}while( !( strlen(carBran) < MAX_LENGTH && strlen(carBran) > 0 ) );
		system("pause");
		break;
		case 7:
		if (pFirst == NULL)
		{	printf("\nThe CAR CATALOGUE is Empty, there are no cars to be searched/ displayed!\n");system("pause");break;}
		do{
			fflush(stdin);
			printf("\nEnter a car brand |Character set of up to 20 symbols|: "); 
			if(gets(carBran) == NULL)//the Ctrl/Z combination
			{
				printf("\nError in initialization!\n");
				break;
			}
			if(carBran[0] == '\0')//if nothing has been entered
			{
				printf("\nError, nothing has been entered, try again!\n");
				break;
			}
			else
			{
				average = brandAvg(&pFirst, carBran);
				if(average != average){ printf("\n\nThe car brand you have entered is NOT in the CAR CATALOGUE!\n\n"); break;}
				printf("\nThe Average Car Price for brand %s is: %f\n",carBran ,average);
				displAllGAvgForBrand(&pFirst, carBran, average);
			}
		}while( !( strlen(carBran) < MAX_LENGTH && strlen(carBran) > 0 ) );
		system("pause");
		break;
		case 8: 
		if (pFirst!=NULL)
		removeList(&pFirst);
		printf("\nThe CAR LIST is Empty!\nProgram exiting...\n");
		break;
	default:
	printf("\nBad choice! \n");
	system("pause");
	}
	}while(mode != 8); // eight because the list gets destroyed and we exit the program
	return 0;
	}