示例#1
0
void printT(struct TreeNode* root){
	if(root==NULL){

	}else{
		printf("%c ",(char)root->val) ;
		printT(root->left) ;
		printT(root->right) ;
	}
}
static cl_int printPI_t(cl_program program)
{
    cl_int err;
    T* value;
    size_t size=0;
    //Get size
    err = clGetProgramInfo( program,
                            I,
                            0,
                            0,
                            &size
                          );
   
    if ( err != CL_SUCCESS )
    {
        printf("Couldn't get Program property size.");
        return err;
    }

    value = (T*) malloc(size);
    if ( value == 0 )
    {
        printf("Failed to malloc");
        return CL_OUT_OF_HOST_MEMORY;
    }

    err = clGetProgramInfo( program,
                            I,
                            size,
                            value,
                            0
                          );

    if ( err != CL_SUCCESS )
    {
        printf("Failed to get program info property.");
        free(value);
        return err;
    }

    // Use Overloaded printT
    if (! isArray ) printT(*value);
    else
    {
        for(unsigned int i=0; i < size/sizeof(T); ++i)
        {
            printT(value[i]);
            printf(", ");
        }
    }
    free(value);

    return CL_SUCCESS;
}
示例#3
0
int main(){
	int array[] = {2,3,4,6,7,9,13,15,17,18,20} ;
	struct TreeNode* root = sortedArrayToBST(array,11) ;
	printT(root) ;
	printf("\n") ;
	return 0 ;
}
示例#4
0
int main(){
	struct TreeNode* bst = NULL ;
	int array[] = {15,6,18,3,7,17,20,2,4,13,9} ;
	for(int i=0;i<11;i++){
		insertNode(&bst,array[i]) ;
	}
	
	printT(bst) ;
	printf("\n") ;
	return 0 ;
}
static cl_int printDI_t(cl_device_id did, cl_device_info info)
{
    cl_int err;
    T param;
    err = clGetDeviceInfo( did,
                           info,
                           sizeof(T),
                           &param,
                           0
                         );
    if ( err != CL_SUCCESS)
    {
        printf("Could not get information for generic type\n");
        return err;
    }

    printT(param);
    return CL_SUCCESS;
}
示例#6
0
文件: main.c 项目: knowlet/Adv.DS-HW
int main(int argc, const char * argv[])
{
    treeNode* avlTree = NULL;
    bool unbalanced = false;
    char code = 0;
    int key = 0;
    while (toupper(code) != 'X') {
        // printf("Enter 'I' to insert node, 'D' to delete node, 'C' to clear the tree, 'S' to show tree, 'X' to exit: ");
        scanf("%s", &code);
        switch (toupper(code)) {
            case 'I':
                // printf("Enter the value of node: ");
                scanf("%d", &key);
                avlInsert(&avlTree, key, &unbalanced);
                break;
                
            case 'D':
                // printf("Enter the value of node: ");
                scanf("%d", &key);
                avlErase(&avlTree, key, &unbalanced);
                break;
                
            case 'C':
                freeTree(avlTree);
                avlTree = NULL;
                unbalanced = false;
                break;
                
            // case 'S':
                // horizonDisplay(avlTree, avlTree, 1);
                // puts("");
                
            default:
                break;
        }
        printT(avlTree);
    }
    // printf("cleaning up...");
    freeTree(avlTree);
    // puts("\nGood bye~");
    return 0;
}
static cl_int printCI_t(cl_context context, cl_context_info prop)
{
    cl_int err;
    T value;
    err = clGetContextInfo(context,
                           prop,
                           sizeof(T),
                           &value,
                           0
                          );

    if ( err != CL_SUCCESS )
    {
        printf("Couldn't get generic platform property");
        return err;
    }

    printT(value);
    return CL_SUCCESS;
}
	void printT(TreeNode *node){
		if(!node)return;
		cout<<node->val<<" ";
		printT(node->left);
		printT(node->right);
	}
示例#9
0
int MYspawnve(int wait, char *script, char const **argv, char **envp)
{
    RTN_TYPE rtn = 0;
    int      pid = 0;
    
#if defined(INTEL_NT) || defined(INTEL_9X)
    static char *shell = NULL;
    
    if (NULL == shell)
    {
       //char const *local = findExec("sh.exe");
       char const *local = Tenv::appGet("SHELL");
       shell = new char [strlen(local) +1];
       strcpy(shell, local);
    }
    
    char  *(MYargv[1024]);
    char **p;
    char **q;
    
    MYargv[0] = shell;
    MYargv[1] = script;
    
    for (p = argv +1, q = MYargv +2; (NULL != *p); p++, q++)
       *q = *p;
       
    *q = NULL;

    if (MY_WAIT == wait)
       rtn = spawnve(_P_WAIT, shell, (const char* const*)MYargv, (const char* const*)envp);
    else 
       pid = spawnve(_P_NOWAIT, shell, (const char* const*)MYargv, (const char* const*)envp);
    
#else

#if defined(CYGWIN)  /* 006 */
    static char *shell = NULL;

    if (NULL == shell)
    {
       char const *local = Tenv::appGet("SHELL");
       shell = new char [strlen(local) +1];
       strcpy(shell, local);
    }

    char  *(MYargv[1024]);
    char **p;
    char **q;

    MYargv[0] = shell;
    MYargv[1] = script;

    for (p = argv +1, q = MYargv +2; (NULL != *p); p++, q++)
       *q = *p;

    *q = NULL;
    argv = MYargv;
    script = shell;
#endif
      
   if (0 == (pid = fork()))
   {
      // Child
      
      execve(script, (char**)argv, envp);
      printE("Executeable [%s] not found or not executable\n", script);
      exit(-1);
   }
   else if (-1 < pid)
   {
      // Parent
      
      if (MY_WAIT == wait)
      {
         waitpid(pid, &rtn, 0);
      }
   }
   else
   {
      // Fork fail
      printT("Fork failed [-1]\n");
      return (-1);
   }
   
#endif
      
    if (MY_WAIT == wait)
    {
        return(RTN_VALUE(rtn));
    }
    else
    {
        return(pid);
    }
}
示例#10
0
int execute  (char const *comm, char **envp)
{
   int         status = 0;
   char const *(argv[1024]);
   char const *script;
   char const *shell = Tenv::appGet("SHELL");
   
   if (NULL == comm) return(0);
   
   if ('\0' == *comm)
   {
      status = 0;
   }
   else if ((shell == NULL) || !strcmp(shell, INTERNAL_SHELL))
   {
   	  // Use the internal shell
      int rtn;
      int i;
      
      // Pass on the target and dependents as arguments
      Tstr target = Tenv::appGet("TARGET");
      Tstr deps   = Tenv::appGet("DEPS");
         
      char *d = (char*)malloc(strlen((char const*)deps)+1);
      strcpy(d, (char const*)deps);
            
      char *p = d;
      char *q = p;
      
      argv[0] = INTERNAL_SHELL;
            
      argv[1] = (char const*)target;
         
      while (isspace(*p)) p++;
      for (i = 2; (i < 1023) && ('\0' != *p); i++)
      {
         q = p;
         while ((!isspace(*p)) && ('\0' != *p)) p++;
         *(p++) = '\0';
         while (isspace(*p)) p++;
            
         argv[i] = q;
      }
         
      argv[i] = NULL;
            
      rtn = msh(comm, argv, envp);
      
      // Free the space
      free(d);
      
      if (0 != rtn) printT("Build failed [%d]\n", rtn);
      status = rtn;
   }
   else if (NULL != (script = makeScript(comm)))
   {
   	  // Use the internal shell
      int rtn;
      int i;
      
      // Pass on the target and dependents as arguments
      Tstr target = Tenv::appGet("TARGET");
      Tstr deps   = Tenv::appGet("DEPS");
         
      char *d = (char*)malloc(strlen((char const*)deps)+1);
      strcpy(d, (char const*)deps);
            
      char *p = d;
      char *q = p;
      
      argv[0] = INTERNAL_SHELL;
            
      argv[1] = (char const*)target;
         
      while (isspace(*p)) p++;
      for (i = 2; (i < 1023) && ('\0' != *p); i++)
      {
         q = p;
         while ((!isspace(*p)) && ('\0' != *p)) p++;
         *(p++) = '\0';
         while (isspace(*p)) p++;
            
         argv[i] = q;
      }
         
      argv[i] = NULL;
            
      rtn = MYspawnve(MY_WAIT, (char*)script, argv, envp);
      
      // Free the space
      free(d);
      
      unlink((char*)script);
      
      if (0 != rtn) printT("Build failed [%d]\n", rtn);
      status = rtn;
   }
   
   return(status);
}