void print_road(pair<bi_node, bi_node> meet_pos,
		bi_node **s)
{//meet_pos中是两队列相遇处的两节点
 //其中first是q_beg队列中的节点,second是q_end队列中的节点
 //这两个点是相邻的
 //输出路径时向后递归逆序输出q_beg的路径,向前顺序输出q_end的路径
	print_backward(s[meet_pos.first.b_y][meet_pos.first.b_x], s);
	print_forward(s[meet_pos.second.b_y][meet_pos.second.b_x], s);
}
Exemplo n.º 2
0
static void
switch_on_type(struct mlist *mlp, struct tdesc *tdp, char *format, int level)
{
	boolean_t allocated = B_FALSE;

	if (format == NULL) {
		allocated = B_TRUE;
		format = uc(mlp->name);
	}

	switch (tdp->type) {
	case INTRINSIC:
		print_intrinsic(mlp, tdp, format, level);
		break;
	case POINTER:
		print_pointer(mlp, tdp, format, level);
		break;
	case ARRAY:
		print_array(mlp, tdp, format, level);
		break;
	case FUNCTION:
		print_function(mlp, tdp, format, level);
		break;
	case UNION:
		print_union(mlp, tdp, format, level);
		break;
	case ENUM:
		print_enum(mlp, tdp, format, level);
		break;
	case FORWARD:
		print_forward(mlp, tdp, format, level);
		break;
	case TYPEOF:
		print_typeof(mlp, tdp, format, level);
		break;
	case STRUCT:
		print_struct(mlp, tdp, format, level);
		break;
	case VOLATILE:
		print_volatile(mlp, tdp, format, level);
		break;
	default:
		fprintf(stderr, "Switch to Unknown type\n");
		error = B_TRUE;
		break;
	}
	if (allocated)
		free(format);
}
Exemplo n.º 3
0
/* Need to store just the part of the query specified (e.g., 1..10) */
static void
print_interval_centered (char *divstring, Chrpos_T coordstart, int index, IIT_T iit, int fieldint) {
  Interval_T interval;
  char *label, *annotation, *restofheader, centerchar;
  bool allocp;
  int annotlength, left, centerpos;

  if (fieldint < 0) {
    annotation = IIT_annotation(&restofheader,iit,index,&allocp);
    if (allocp == true) {
      FREE(restofheader);
    }
  } else {
    annotation = IIT_fieldvalue(iit,index,fieldint);
    allocp = true;
  }
  annotlength = strlen(annotation);
  if (annotation[annotlength-1] == '\n') {
    annotlength--;
  }

  interval = IIT_interval(iit,index);
  left = coordstart - Interval_low(interval); /* + length(query) - queryend */
  if (Interval_sign(interval) < 0) {
    centerpos = annotlength-left-1;
  } else {
    centerpos = left;
  }
  centerchar = annotation[centerpos];

  if (centeruc == true && islower(centerchar)) {
    if (fieldint >= 0 && allocp == true) {
      FREE(annotation);
    }
  } else {
    print_spaces(centerlength-left);
    if (Interval_sign(interval) < 0) {
      print_complement(annotation,annotlength-1,centerpos+1);
      printf("[%c]",complCode[(int) centerchar]);
      print_complement(annotation,centerpos-1,0);
    } else {
      print_forward(annotation,0,centerpos-1);
      printf("[%c]",centerchar);
      print_forward(annotation,centerpos+1,annotlength-1);
    }
    print_spaces(centerlength+left-annotlength);
    if (fieldint >= 0 && allocp == true) {
      FREE(annotation);
    }
  
    printf("\t");
    if (Interval_type(interval) > 0) {
      printf("%s\t",IIT_typestring(iit,Interval_type(interval)));
    }

    if (divstring != NULL) {
      if (Interval_sign(interval) < 0) {
	printf("-%s:",divstring);
      } else {
	printf("+%s:",divstring);
      }
    }

    if (signedp == false) {
      printf("%u..%u",Interval_low(interval),Interval_high(interval));
    } else if (Interval_sign(interval) < 0) {
      printf("%u..%u",Interval_high(interval),Interval_low(interval));
    } else {
      printf("%u..%u",Interval_low(interval),Interval_high(interval));
    }
    printf("\t");

    label = IIT_label(iit,index,&allocp);
    printf("%s",label);
    if (allocp == true) {
      FREE(label);
    }
    printf("\n");
  }

  return;
}
int main(void)
{
	int wartosc;
	int pozycja;
	int flaga=1;
	int wyb;
	lista *test=stworz();

	while(flaga==1)
	{
		druk_menu(999);
		scanf("%d", &wyb);
		system("cls");
		druk_menu(wyb);
		switch(wyb)
		{
		case 1:
			printf("podaj wartosc: ");
			scanf("%d", &wartosc);
			push_front(test, wartosc);
			printf("umieszczono na liscie\n");
			break;
		case 2:
			printf("podaj wartosc: ");
			scanf("%d", &wartosc);
			push_back(test, wartosc);
			printf("umieszczono na liscie\n");
			break;
		case 3:
			printf("podaj wartosc: ");
			scanf("%d", &wartosc);
			printf("podaj pozycja: ");
			scanf("%d", &pozycja);
			if(pozycja<=test->rozmiar && pozycja>0)
			{
				insert(test, pozycja, wartosc);
				printf("umieszczono na liscie\n");
			}
			else
				printf("pozycja ktora wybrales jest niewlasciwa\nlub na liscie jesty tylko jeden element\n");
			break;
		case 4:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
			{
				printf("twoja liczba to: %d\n", pop_front(test));
			}
			break;
		case 5:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
			{
				printf("twoja liczba to: %d\n", pop_back(test));
			}
			break;
		case 6:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
			{
				printf("podaj pozycje: ");
				scanf("%d", &pozycja);
				if(pozycja<=test->rozmiar && pozycja>0)
					printf("twoja liczba to: %d\n", remove_l(test, pozycja));
				else
					printf("pozycja ktora wybrales jest niewlasciwa\n");
			}
			break;
		case 7:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
			{
				printf("podaj pozycje: ");
				printf("twoja liczba to: %d\n", front(test));
			}
			break;
		case 8:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
			{
				printf("podaj pozycje: ");
				printf("twoja liczba to: %d\n", back(test));
			}
			break;
		case 9:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
			{
				printf("podaj pozycje: ");
				scanf("%d", &pozycja);
				if(pozycja<=test->rozmiar && pozycja>0)
					printf("twoja liczba to: %d\n", at(test, pozycja));
				else
					printf("pozycja ktora wybrales jest niewlasciwa\n");
			}
			break;
		case 10:
			clear(test);
			printf("lista wyczyszczona\n");
			break;
		case 11:
			printf("rozmiar listo wynosi: %d\n", size(test));
			break;
		case 12:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
				printf("lista posiada elementy\n");
			break;
		case 13:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
				printf("adres pierwszego elementu to %p\n", begin(test));
			break;
		case 14:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
				printf("adres ostatniego elementu to %p\n", end(test));
			break;
		case 15:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
				print_forward(test);
			break;
		case 16:
			if(isEmpty(test))
				printf("lista jest pusta\n");
			else
				print_backward(test);
			break;
		case 0:
			flaga=0;
			break;
		default:
			printf("wybrales zle\nsprobuj ponownie\n");
			break;
		}
		printf("\n> > > potwierdz enterem < < <\n");
		fflush(stdin);
		getchar();
		system("cls");
	}

	destroy(test);
	return 0;
}
void print_forward(bi_node f, bi_node **s)
{//从点f向终点输出路径
	cout << " (x:" << f.b_x << ",y:" << f.b_y << ")" << endl;
	if(f.b_fa.first != -1 && f.b_fa.second != -1)
		print_forward(s[f.b_fa.second][f.b_fa.first], s);
}
Exemplo n.º 6
0
int main(){

	int options;
	printf("\nWelcome to The Song Database.");

	while (options != 5) {
		options = intro();
		if (options == 1) {
			char* artist;	
			char* album;
			char* song_title;
			char* date;
			char* song_time_char;	
			int song_time;

			artist = malloc (MAX_SIZE);
			album = malloc (MAX_SIZE);
			song_title = malloc (MAX_SIZE);
			date = malloc (MAX_SIZE);
			song_time_char = malloc (MAX_SIZE);

			printf ("\nPlease enter the artist name: ");
			fgets (artist, MAX_SIZE, stdin);
		   	if ((strlen(artist)>0) && (artist[strlen (artist) - 1] == '\n'))
				artist[strlen (artist) - 1] = '\0';

			printf ("Please enter the album name: ");

			fgets (album, MAX_SIZE, stdin);
		   	if ((strlen(album)>0) && (album[strlen (album) - 1] == '\n'))
				album[strlen (album) - 1] = '\0';

			printf("Please enter the song title: ");
			fgets (song_title, MAX_SIZE, stdin);
		   	if ((strlen(song_title)>0) && (song_title[strlen (song_title) - 1] == '\n'))
				song_title[strlen (song_title) - 1] = '\0';

			printf("Please enter the date: ");
			fgets (date, MAX_SIZE, stdin);
		   	if ((strlen(date)>0) && (date[strlen (date) - 1] == '\n'))
				date[strlen (date) - 1] = '\0';


			printf("Please enter song time: ");
			fgets(song_time_char, MAX_SIZE, stdin);
			if ((strlen(song_time_char)>0) && (song_time_char[strlen (song_time_char) - 1] == '\n'))
				song_time_char[strlen (song_time_char) - 1] = '\0';
			song_time = atoi(song_time_char);

			pushItem(artist, album, song_title, date, song_time);
			
			free(artist);
			free(album);
			free(song_title);
			free(date);
			free(song_time_char);

		}
	
		else if (options == 2) {
			delete_artist();
		}
	
		else if (options == 3) {
			if (head == NULL) {
				printf("\nNo entries found\n");
			}
			else {
				printf("\nPrinting it forward:\n");
				print_forward(head);
			}
		}

		else if (options == 4) {
			if (head == NULL) {
				printf("\nNo entries found\n");
			}
			else {
				printf("\nPrinting it backward\n");
				print_backward(tail);
			}
		}
	
		else if (options == 5) {

			freeEverything(head);
			printf("\nGoodbye.\n");
			break;
		}

		else {
			printf("\nNo Valid Input\n");	
		}
	}
	return 0;
}