Example #1
0
int main() {

	mongo conn[1];
	int status = mongo_client(conn, "127.0.0.1", 27017);
	
	if (status != MONGO_OK) {
		switch(conn->err) {
			case MONGO_CONN_NO_SOCKET: 	printf("no socket\n"); return 1;
			case MONGO_CONN_FAIL: 		printf("connection failed\n"); return 1;
			case MONGO_CONN_NOT_MASTER: 	printf("not master\n"); return 1;
		}
	}
	char target1[] = "Pitt, Brad";
	char target2[] = "Foxx, Jamie";	

	if (strcmp(target1, target2) == 0) { printf("same guy, dipshit\n"); exit(1); }

	/* 
	The program is given a movie and it finds the cast of that movie in the 
	form of a linked list.
	*/
	printf("actor for inglorious basterds\n");
	struct node *root;
	root = getActors("Inglourious Basterds (2009", conn);
	struct node *conductor;
	conductor = root;
	if (conductor != 0) {
		while (conductor->next != 0) {
			printf("%s\n", conductor->x);
			conductor = conductor->next;
		}
		printf("%s\n", conductor->x);
	}
	
	/* 
	The program is given an actor and it finds all the movies that person has 
	starred in, in the form of a linked list. 
	*/
	printf("movies for brad pitt\n");
	struct node *root2;
	root2 = getMovies(target1, conn);
	struct node *conductor2;
	conductor2 = root2;
	if (conductor2 != 0) {
		while(conductor2->next != 0) {
			printf("%s\n", conductor2->x);
			conductor2 = conductor2->next;
		}
		printf("%s\n", conductor->x);
	}
	
	mongo_destroy(conn);
	return 0;

}
Example #2
0
void
show_movies(){
	List_Movies list;
	char times[5][5];
	int i=0;
	list=getMovies();
	getTimes(times);
	
	for(; i<CANT_MOVIES; i++){
		printf("%s - %s\n", list.movies_list[i].id, list.movies_list[i].name);
	}
	printf("\n");
	printf("Available times:\n");
	for(i=0; i<5; i++){
		printf("%s     ", times[i]);
	}
	printf("\n");
}
Example #3
0
PathNode* BFS(char * start,char * target){
	printf("Start:%s Target:%s \n",start,target);

	Node* head = NULL;
	Node* tail = NULL;

	int i;
	int j;


	PathNode *toAdd = malloc(sizeof(PathNode));
	memset(toAdd, 0, sizeof(PathNode));

	toAdd->movie = malloc(sizeof(char)*65);
	memset(toAdd->movie, 0, sizeof(char)*65);
	strcpy(toAdd->movie,"START");

	toAdd->actor = malloc(sizeof(char)*65);
	memset(toAdd->actor, 0, sizeof(char)*65);
	strcpy(toAdd->actor,start);
	toAdd->nextPath = NULL;

	Node *newNode = malloc(sizeof(Node));
	newNode->value = toAdd;
	newNode->nextNode = NULL;
	enqueue(&head,&tail,&newNode);

	printQueue(head);
		
	puts("Using queue");
	while(1){
		Node *toCheck = dequeue(&head,&tail);
		PathNode *path = toCheck->value;
		char * prevActor = path->actor;

		strlist *allMovies = getMovies(prevActor);

		for(i = 0; i< allMovies->len; i++){
			printQueue(head);
			char * movie = allMovies->items[i];

			printf("Checking movie: #%i %s\n",i, movie);

			strlist * allActors = getActors(movie);
			printf("Actors Len: %i\n",allActors->len);

			for(j = 0; j< allActors->len; j++){

				char * actor = allActors->items[j];
				printf("Checking actor: #%i %s\n",j, actor);

				if(strcmp(actor,prevActor)){
					PathNode *toAdd = malloc(sizeof(PathNode));
					memset(toAdd, 0, sizeof(PathNode));

					toAdd->movie = malloc(sizeof(char)*65);
					memset(toAdd->movie, 0, sizeof(char)*65);
					strcpy(toAdd->movie,movie);

					toAdd->actor = malloc(sizeof(char)*65);
					memset(toAdd->actor, 0, sizeof(char)*65);
					strcpy(toAdd->actor,actor);

					toAdd->nextPath = path;

					if (!strcmp(target,actor)){
						return toAdd; 
					}else{
						Node *newNode = malloc(sizeof(Node));
						newNode->value = toAdd;
						newNode->nextNode = NULL;
						enqueue(&head,&tail,&newNode);
						//printQueue(head);
					}
				}
			}
		}
		free(toCheck);
	}
}