예제 #1
1
void main()
{
char op;

op=meniu();
while (op!=5)
{
switch (op)
{
case '1': creare();   break;
case '3': adauga();   break;
case '2': deschide(); break;
case '4': sterge();   break;
default: op=meniu(); break;
}
op=meniu();
}
exit(1);
}
예제 #2
0
Arb sterge(Arb *arb,int x)
{
	Arb tmp;
	tmp=(Nod*)malloc(sizeof(Nod));
	if ((*arb)==NULL)
	{
		//printf("Nodul nu a fost gasit");
	}
	else
	{
		if ((**arb).val>x)
		{
			(**arb).st=sterge(&((**arb).st),x);
		}
		else
		{
			if ((**arb).val<x)
				{
					(**arb).dr=sterge(&((**arb).dr),x);
				}
			else
			{
				//am gasit elementul.o luam pe cele3 cazuri
				if (((**arb).st!=NULL)&&((**arb).dr!=NULL))
				{
					tmp=minim((**arb).dr);
					(**arb).val=(*tmp).val;
					(**arb).dr=sterge(&((**arb).dr),x);//la o recitire nu am inteles linia asta de cod..s-ar putea sa trebuiasca sa ramana doar ce e dupa egal.
					
				}
				else
				{
					tmp=(*arb);
					if ((**arb).st!=NULL)
						(*arb)=(**arb).st;
					else
						(*arb)=(**arb).dr;
				free(tmp);
				}
				
			}
		}
	}
return (*arb);
}
예제 #3
0
int main()
{
	Arb arb,gas;
	
	int x,i;	 
	arb=NULL;
	srand(time(NULL));
	for (i=1;i<30;i++)
	{
		x=rand();
		x=x%30;
		inserare(&arb,x);
	}
	//inordine(arb,0);
	//printf("\n\n\n");
	gas=find(arb,x);
	if (gas!=NULL)
		printf("%d",(*gas).val);
	//preordine(arb,0);
	sterge(&arb,5);
	//preordine(arb,0);
	return 0;
}
예제 #4
0
static void sterge(const char * dir_name)
{
  DIR * d;
  d = opendir(dir_name);

  /* 
  * Verificam daca folderul poate fi deschis.
  */
  if(!d)
  {
    fprintf (stderr, "Nu pot deschide directorul'%s': %s\n",
     dir_name, strerror (errno));
    exit(1);
  }
  while(1){
    struct dirent * child;
    char * d_name;
    char * delete_path;
    /* "Readdir" ia fisierele din d. */
    child = readdir(d);
        /* Iesi daca nu mai sunt fisiere. */
    if(!child)
      break;

    d_name = child->d_name;
    /* Printeaza numele.
     * DELETE: cale, daca fisierul trebuie sters.
     * cale simpla daca fisierul nu trebuie sters
     */
     if(strstr(d_name,".out"))
     {
      char* file = malloc(strlen(dir_name) + strlen(d_name) + 2);
      printf("DELETE: %s/%s\n", dir_name, d_name);
      strcpy(file,dir_name);
      strcat(file,"/");
      strcat(file,d_name);
      remove(file);
      free(file);
    }
    else
      printf("%s/%s\n", dir_name, d_name);

    /* Vezi daca e subdirector pentru "d". */
    if(child->d_type & DT_DIR)
    { 
    /* Vezi daca nu e d sau parintele lui d. */

      if(strcmp(d_name, "..") != 0 && strcmp(d_name, ".") != 0)
      {
        int path_length;
        char path[PATH_MAX];
    /* Concatenam in path fisierul la care s-a ajuns. */
        snprintf(path, PATH_MAX, "%s/%s", dir_name, d_name); 
    /* Chemam recursiv "sterge" pentru noua cale. */
        sterge(path);
      }
    }
  }
/* Verificam daca folder-ul se poate inchide. */
  if(closedir(d)){
    fprintf (stderr, "Nu pot inchide '%s': %s\n",
     dir_name, strerror (errno));
    exit(1);
  }
  
}
예제 #5
0
int main(int argc, char const *argv[])
{
  char file[100];
  sterge(argv[1]);
  return 0;
}