void findFive() {
	struct node *temp;
	int findFlag = 0;
	temp = head;
	while (temp != NULL)
	{
		if (temp->num == 5) {
			printf("%d\n", temp->order);
			findFlag = 1;
			printf("====  是否继续查找下一个值为5的节点?1.是\t2.否  ====\n");
			int choice;
			scanf("%d", &choice);
			switch (choice)
			{
			case 1:
				findFlag = 0;
				break;
			case 2:
				showChoice();
				return;
				break;
			default:
				break;
			}
		}
		temp = temp->next;
	}
	if (!findFlag)
	{
		printf("%d\n", -1);
	}
	showChoice();
}
void showChoice() {
	int choice;
	printf("====  请输入你的选择:  ====\n<1.创建链表/添加节点>\t<2.遍历链表>\n<3.反序链表>\t<4.查找值为5>\t<5.退出>\n");
	scanf("%d", &choice);
	switch (choice)
	{
	case 1:
		create();
		break;
	case 2:
		showValue();
		break;
	case 3:
		turnOrder();
		break;
	case 4:
		findFive();
		break;
	case 5:
		break;
	default:
		printf("====  输入错误,请重新输入  ====\n");
		showChoice();
		break;
	}
}
void showValue() {
	struct node *temp;
	temp = head;
	printf("\n");
	while (temp != NULL)
	{
		printf("## 节点%d的值为:\t%d\t##\n", temp->order, temp->num);
		temp = temp->next;
	}
	printf("\n");
	printf("====  链表打印结束,现返回菜单  ====\n");
	showChoice();
}
void create() {
	struct node *p1;
	p1 = (struct node*)malloc(sizeof(struct node));
	printf("<节点%d的地址:%d>  请输入节点%d的值:", ++totalPointSum, p1, totalPointSum);
	scanf("%d", &p1->num);
	p1->order = totalPointSum;
	p1->next = NULL;
	if (head != NULL)
	{
		tail->next = p1;
		tail = p1;
		printf("====  添加节点完成,现返回菜单  ====\n");
		showChoice();
	}
	else
	{
		head = p1;
		tail = p1;
		printf("====  创建表头完成,现返回菜单  ====\n");
		showChoice();
	}
}
void turnOrder() {
	struct node *temp,*tempNext,*temp2,*temp3;
	temp = head;
	temp3 = head;
	tempNext = temp->next;
	temp2 = tempNext;
	head->next = NULL;
	while (tempNext != NULL)
	{
		tempNext = tempNext->next;
		temp2->next = temp;
		temp = temp2;
		temp2 = tempNext;
	}
	head = tail;
	tail = temp3;
	printf("====  反序完成,现返回菜单  ====\n");
	showChoice();

}
Beispiel #6
0
/** The event Receiver main loop
  *
  * \param event The event
  */
bool RainbruRPG::Events::erCreatePerso::OnEvent(SEvent event){

  if (event.EventType == EET_GUI_EVENT){
    s32 id = event.GUIEvent.Caller->getID();
    IGUIEnvironment* env=GameEngine::getSingleton().getIrrlichtGui();
    irr::IrrlichtDevice * device  = GameEngine::getSingleton().
                                    getIrrlichtDevice();


    IGUIElement *root= env->getRootGUIElement();
    if (!root)
      LOGW("Failed to get IGUIEnvironment root element");

    // Mouse events
    switch(event.GUIEvent.EventType){
		  
      /*
	If a button was clicked, it could be one of 'our'
	three buttons. If it is the first, we shut down the engine.
	If it is the second, we create a little window with some 
	text on it. We also add a string to the list box to log
	what happened. And if it is the third button, we create
	a file open dialog, and add also this as string to the list box.
	That's all for the event receiver.
      */
    case EGET_BUTTON_CLICKED:

      if (id == 101){ //Create account bouton
	LOGI("CREATE button has been clicked");

	// Get the user edit box content
	if (root){
	  controlBefore(root);
	}

	return true;
      }
      else if (id == 102){ //roll bouton
	LOGI("ROLL button was clicked");
	roll(root, this);
	return true;
      }
      else if (id == 103){ //cancel bouton
	LOGI("CANCEL creation window button was clicked");
	GameEngine::getSingleton().changeState(ST_PERSO_LIST);
	return true;
      }
      else if (id == 10001){ //OK
	LOGI("OK button was clicked");
	if (controlBefore(root)){
	  if (changeButtonId!=-1){
	    if (winSelect){
	      LOGI("Removing winSelect");
	      winSelect->setVisible(false);
	      winSelect->remove();
	    }
	    
	    IGUIElement* guiE=root->getElementFromId(changeButtonId, true);
	    if (guiE!=0){
	      if (guiE->getType()!= 1){ // WIDGET_TYPE
		LOGW("The changeButtonId is not a button id");
	      }
	      LOGI("The 'change' button caption should have change");
	      cout << "[ercreateperso.cpp::107]listBoxVal=" <<listBoxVal<<endl;
	      stringw valw=StringConv::getSingleton().stow(listBoxVal);
	      this->removePreselectionModidifers();
	      guiE->setText(valw.c_str()); 
	      this->changePersoFormModifier();
	    }
	    else{
	      LOGW("Cannot get the 'change' button : getElementFromId failed");
	    }
	    
	  }
	  else{
	    LOGW("Cannot get the 'change' button : changeButtonId=-1");
	  }
	} // if (controlBefore(root))
	else{
	  LOGW("ControlBefore failed");
	  env->addMessageBox (L"Creation failed", 
			      L"You must make a choice.");

	}
      }
      else if (id == 10002){ //Cancel
	LOGI("CANCEL select window button was clicked");
	if (winSelect){
	  LOGI("Removing winSelect");
	  winSelect->setVisible(false);
	  winSelect->remove();
	}

      }
      else{
	handleBonusFileButton(id, root, this);
      }
      break;

    case EGET_LISTBOX_CHANGED:
      if (id == 10000){ //Choices listbox
	showChoice(event.GUIEvent.Caller);
	return true;
      }
      break;
    }
  }
  
  return false;

}
void main() {
	head = NULL;
	showChoice();
}