Beispiel #1
0
void XGStart()
{
  char thePDumpFile[80], thePDFRoot[80];

  strncpy(thePDFRoot,theDumpFile,findlen(theDumpFile));
  thePDFRoot[findlen(theDumpFile)] = '\0';
  while (!theExitFlag) {
    if (theRunWithXFlag == TRUE) {
      SortWindows();
      if(numberOfSpecials!=0)
	if(Tcl_Eval(interp,"CreateSpecialDialog\n")!=TCL_OK) {
	  printf("Error creating Special Dialog\n");
	  printf("%s\n",interp->result);
	}
      sprintf(TclCommand,"UpdateTime %g ; DoGraphics; update idletasks\n",*theTimeStep);
      /* Tcl_Eval(interp,TclCommand);  put below */
      if(Tcl_Eval(interp,"Tk_XGStart\n")!=TCL_OK) {
	printf("Error calling Tk_XGStart\n");
      }
      Tcl_Eval(interp,TclCommand); 

      if (theNumberOfSteps != 0) {
	Tcl_Eval(interp,".lbframe.run invoke\n");
      }
      
      /* Change the procedure for the HUP signal. */
      signal(SIGUSR1, Signal_KillGraphicsProc);

      Tk_MainLoop();
    }
    
    if (theRunWithXFlag == FALSE) {
      signal(SIGUSR1, Signal_RestoreGraphicsProc);
      
      while ((theNumberOfSteps==0 || theCurrentStep<=theNumberOfSteps) && 
	     (theRunWithXFlag == FALSE)) {
	XGMainLoop();
	if (theDumpPeriod!=0 && theCurrentStep%theDumpPeriod==0) {
	  sprintf(thePDumpFile,"%s%d%s",thePDFRoot,
		  theCurrentStep/theDumpPeriod,theDumpExtension);
	  if (theIDumpFlag) Dump(thePDumpFile);
	  else Dump(theDumpFile);
	}
	theCurrentStep++;
      }
      if ((theDumpPeriod!=0) && (theCurrentStep%theDumpPeriod==0)) {
	sprintf(thePDumpFile,"%s%d%s",thePDFRoot,
		theCurrentStep/theDumpPeriod,theDumpExtension);
	if (theIDumpFlag) Dump(thePDumpFile);
	else Dump(theDumpFile);
      }
      if(theCurrentStep>theNumberOfSteps && (theRunWithXFlag == FALSE)) {
	XG_Quit();
      }
      if (theRunWithXFlag == TRUE) StartGraphics();
    }
  }
  XG_Quit();
}
Beispiel #2
0
struct Node *subtract(struct Node *a,  struct Node *b)
{
	if(!a && !b)
		return NULL;
	if(!a )
		return b;
	if(!b)
		return a;
	
	//  find length
	
	int len1 =  findlen(a);
	int len2 =  findlen(b);
	
	struct Node *sl ;
	struct Node *ll;
	struct Node *a1 =  a;
	struct Node *b1 = b;
	if(len1 == len2)
	{
		while (a->data == b->data)
		{
			if(a->data != b->data)
			{
				sl =  a->data<b->data? a1:b1;
				ll =  a->data>b->data? a1:b1;			
				break ;
			}
			a = a->next;
			b = b->next;
			
		}
		
	}else
	{
		printf("ss");
		sl =  len1<len2? a:b;
		ll = len1>len2? a:b;
		
		sl =  appendZeros(sl, (len1-len2));
		
		
	}
	printf("ss");
	int c =0;
	return subtractUtil(sl, ll, &c);
	
	
}
int linkedListMedian(struct node *head) {
	if (head != NULL){
		struct node *temp = head;
		int len = findlen(head),medium;
		if (len == 1){
			medium = temp->num;
			return medium;
		}
		int t = len / 2;
		while (t > 1){
			temp = temp->next;
			t--;
		}
		if (len % 2 == 0){
			medium = ((temp->num) + (temp->next->num))/2;
			return medium;
		}
		else{
			medium = (temp->next)->num;
			return medium;
		}
	}
	else{
		return -1;
	}
}
Beispiel #4
0
void DoMain(ClientData cl)
{
  char thePDumpFile[80], thePDFRoot[80];

  strncpy(thePDFRoot,theDumpFile,findlen(theDumpFile));
  thePDFRoot[findlen(theDumpFile)] = '\0';
  sprintf(TclCommand,"update \n");
  Tcl_Eval(interp,TclCommand);
  /* printf("c domain\n"); */
  if (theNumberOfSteps==0 || theCurrentStep<=theNumberOfSteps) {
    int il;
    for(il=0;il<iterationsPerXUpdate;il++) {
      XGMainLoop();
      if (theDumpPeriod!=0 && theCurrentStep%theDumpPeriod==0) {
	sprintf(thePDumpFile,"%s%d%s",thePDFRoot,
		theCurrentStep/theDumpPeriod,theDumpExtension);
	if (theIDumpFlag) Dump(thePDumpFile);
	else Dump(theDumpFile);
      }
      theCurrentStep++;
    }
#ifdef Tcl75_Tk41
    Tcl_CreateTimerHandler(0, DoGraphics,(ClientData)NULL);
#endif
#ifdef Tcl74_Tk40
    Tk_CreateTimerHandler(0, DoGraphics,(ClientData)NULL);
#endif
  } else {
    if(theExitFlag) {
      if ((theDumpPeriod!=0) && (theIDumpFlag)) {
	sprintf(thePDumpFile,"%s%d%s",thePDFRoot,
		theCurrentStep/theDumpPeriod+1,theDumpExtension);
	Dump(thePDumpFile);
      } 
      else Dump(theDumpFile);
      XG_Quit();
    } else {
      theNumberOfSteps = 0;
      Tcl_Eval(interp,".lbframe.run invoke\n");
      Tcl_Eval(interp,".lbframe.save invoke\n");
    }
  }
}
Beispiel #5
0
void removeDups(char* input)
{   
    int tail = 1;
    int len = findlen(input);
    int i, j;

    for(i=1; i<=len-1;i++)
    {
        for(j = 0; j<tail; j++)
        {
            if(input[i] == input[j])
            {
                break;
            }    
        }
        if( j == tail)
        {
            // no dups found
            input[j] = input[i];
            tail++;
        }
    }
    input[tail] = '\0';
}