Beispiel #1
0
int main(){
    srand(time(NULL));
    spis* tail;
    tail=new spis;
    head=new spis;
    p=new spis;
    
    head=tail;
    head->next=p;
    tail=p;
    
    p=new spis;
    tail->next=p;
    tail=p;
    
    p=new spis;
    tail->next=p;
    tail=p;
    
    tail->next=NULL;
    
    fillrandS(head);
    printS(head);
    filldecS(head);
    printS(head);
    runnumberS(head);
    free(head);
    
    printS(head);
        getch();
    }
Beispiel #2
0
int main(){
	STACK s;
	initStack(&s);
	printS(&s);
	push(&s, 1); push(&s, 2); push(&s, 2); push(&s, 2); push(&s, 2); push(&s, 2); 
	printS(&s);


	return 1;
}
Beispiel #3
0
/*
 *  ======== regsupGetValue ========
 *  Purpose:
 *      Get the value of the entry having the given name.
 */
DSP_STATUS regsupGetValue(char *valName, void *pBuf, u32 *dataSize)
{
	DSP_STATUS retVal = DSP_EFAIL;
	u32 i;

	/*  Need to search through the entries looking for the right one.  */
	for (i = 0; i < pRegKey->numValueEntries; i++) {
		/*  See if the name matches.  */
               if (strncmp(pRegKey->values[i].name, valName,
		    BRIDGE_MAX_NAME_SIZE) == 0) {

			/*  We have a match!  Copy out the data.  */
			memcpy(pBuf, pRegKey->values[i].pData,
			       pRegKey->values[i].dataSize);

			/*  Get the size for the caller.  */
			*dataSize = pRegKey->values[i].dataSize;

			/*  Set our status to good and exit.  */
			retVal = DSP_SOK;
			break;
		}
	}

	if (DSP_SUCCEEDED(retVal)) {
		GT_2trace(REG_debugMask, GT_2CLASS, "G %s DATA %x ", valName,
			  *(u32 *)pBuf);
		printS((u8 *)pBuf);
	} else {
		GT_1trace(REG_debugMask, GT_3CLASS, "G %s FAILED\n", valName);
	}

	return retVal;
}
bool Graph::dijkstra(Vertex &v)
{
  if(vs->size() < 1)
    return false;
 
  set<int> *S = new set<int>();
  S->insert(v.getNodeId());
 
  set<int> *candidate = new set<int>();
  obtainCandidate(*S, *candidate);
  printS(*S);
  printCandidate(*candidate);
 
  vector<vector<int> > *dist = new vector<vector<int> >();
  int u = v.getNodeId();
  vector<int> *vec = new vector<int>(vs->size());
  for(unsigned int i = 0; i < vs->size(); i++)
    vec->at(i) = INT_MAX;
  vec->at(retrieveVertexById(u)) = 0;
  calcShortestPath(vs->at(retrieveVertexById(u)), *vec, *vec);
  dist->push_back(*vec);
 
  printDist(*dist);
 
  for(unsigned int i = 0; i < vs->size() -1; i++)
  {
    vector<int> *vec = new vector<int>();
    bool nextNode = calcShortestPath(vs->at(retrieveVertexById(u)), dist->at(i), *vec);
    if(false == nextNode) // no neighbour node, finish
       return true;
 
    dist->push_back(*vec);
    
    u = selectU(*candidate, *vec);
    S->insert(u);
    printS(*S);
    obtainCandidate(*S, *candidate);
    printDist(*dist);
  }
 
  return true;
}
Beispiel #5
0
void printEnv (size_t step, int n, AQueue aQ, AStack *Events, FILE *out) {
	fprintf(out, "%zu\n", step);
	
	printQ(aQ, print, out);
	fprintf(out, "\n");
	
	for (int i = 0; i < n; ++i) {
		if (!EMPTY_STACK(Events[i])) {
			fprintf(out, "%d: ", i);
			printS(Events[i], print, out);
			fprintf(out, "\n");
		}
	}
	
	fprintf(out, "\n");
}
Beispiel #6
0
int main()
{
	char s[20];
	strcpy(s,"madamimadam");
	printf("Original String: %s.\n",s);
	printf("Palindromes of length greater than/equal to 3:-\n");
	int p[20][20];
	int i,j,si;
	for(i=0; i<20; i++)
		for(j=0; j<20; j++)	
			p[i][j] = 0;
			
	for(i=0; i<19; i++)
	{
		p[i][i] = 1;
		if(s[i] == s[i+1])
		{
			p[i][i+1] = 1;
		}
	}

	for(si=2; si<=19; si++)	
	{
		for(i=0; i<(19-si); i++)
		{
//..considering the values of p[i][i+si]
			if(p[i+1][i+si-1])
				if(s[i] == s[i+si])
					p[i][i+si] = 1;
		}
	}
	
	for(i=0; i<19; i++)
		for(j=0; j<19; j++)
		{
			if(p[i][j] && (j-i >= 2))
			{
				printf("%d-%d:",i,j);
				printS(s,i,j);
			}
		}
	//printMat(p);
	return 0;
}
Beispiel #7
0
/*
 *  ======== regsupEnumValue ========
 *  Purpose:
 *      Returns registry "values" and their "data" under a (sub)key.
 */
DSP_STATUS regsupEnumValue(IN u32 dwIndex, IN CONST char *pstrKey,
			   IN OUT char *pstrValue, IN OUT u32 *pdwValueSize,
			   IN OUT char *pstrData, IN OUT u32 *pdwDataSize)
{
	DSP_STATUS retVal = REG_E_INVALIDSUBKEY;
	u32 i;
       u32 dwKeyLen;
	u32 count = 0;

       DBC_Require(pstrKey);
       dwKeyLen = strlen(pstrKey);

	/*  Need to search through the entries looking for the right one.  */
	for (i = 0; i < pRegKey->numValueEntries; i++) {
		/*  See if the name matches.  */
               if ((strncmp(pRegKey->values[i].name, pstrKey,
		    dwKeyLen) == 0) && count++ == dwIndex) {
			/*  We have a match!  Copy out the data.  */
			memcpy(pstrData, pRegKey->values[i].pData,
				pRegKey->values[i].dataSize);
			/*  Get the size for the caller.  */
			*pdwDataSize = pRegKey->values[i].dataSize;
                       *pdwValueSize = strlen(&(pRegKey->
						values[i].name[dwKeyLen]));
                       strncpy(pstrValue,
				    &(pRegKey->values[i].name[dwKeyLen]),
				    *pdwValueSize + 1);
			GT_3trace(REG_debugMask, GT_2CLASS,
				  "E Key %s, Value %s, Data %x ",
				  pstrKey, pstrValue, *(u32 *)pstrData);
			printS((u8 *)pstrData);
			/*  Set our status to good and exit.  */
			retVal = DSP_SOK;
			break;
		}
	}

	if (count && DSP_FAILED(retVal))
		retVal = REG_E_NOMOREITEMS;

	return retVal;
}
Beispiel #8
0
/*
 *  ======== regsupExit ========
 *  Purpose:
 *      Release all registry support allocations.
 */
void regsupExit(void)
{
	u32 i;

	/*  Make sure data has actually been allocated.  */
	if (pRegKey == NULL) {
		/*  Nothing initialized.return!  */
		return;
	}

	GT_1trace(REG_debugMask, GT_2CLASS, "pRegKey->numValueEntries %d\n",
		  pRegKey->numValueEntries);

	/*  Now go through each entry and free all resources.  */
	for (i = 0; ((i < BRIDGE_MAX_NUM_REG_ENTRIES) &&
	    (i < pRegKey->numValueEntries)); i++) {
		if (pRegKey->values[i].name[0] != '\0') {
			/*  We have a valid entry.free it up!  */
			if (pRegKey->values[i].pData != NULL) {
				GT_3trace(REG_debugMask, GT_2CLASS,
					  "E %d\t %s DATA %x ", i,
					  pRegKey->values[i].name,
					  *(u32 *)pRegKey->values[i].pData);
				printS((u8 *)(pRegKey->values[i].pData));
				MEM_Free(pRegKey->values[i].pData);
			}
			pRegKey->values[i].pData = NULL;
			pRegKey->values[i].dataSize = 0;
			pRegKey->values[i].name[0] = '\0';
		}
	}

	/*  Now that all of the resources are freed up, free the main one!  */
	MEM_Free(pRegKey);

	/*  Don't forget to NULL out the global entry!  */
	pRegKey = NULL;
}
Beispiel #9
0
/*
 *  ======== regsupSetValue ========
 *  Purpose:
 *      Sets the value of the entry having the given name.
 */
DSP_STATUS regsupSetValue(char *valName, void *pBuf, u32 dataSize)
{
	DSP_STATUS retVal = DSP_EFAIL;
	u32 i;

	GT_2trace(REG_debugMask, GT_2CLASS, "S %s DATA %x ", valName,
		  *(u32 *)pBuf);
	printS((u8 *)pBuf);

	/*  Need to search through the entries looking for the right one.  */
	for (i = 0; i < pRegKey->numValueEntries; i++) {
		/*  See if the name matches.  */
               if (strncmp(pRegKey->values[i].name, valName,
		    BRIDGE_MAX_NAME_SIZE) == 0) {
			/*  Make sure the new data size is the same.  */
			if (dataSize != pRegKey->values[i].dataSize) {
				/*  The caller needs a different data size!  */
				MEM_Free(pRegKey->values[i].pData);
				pRegKey->values[i].pData = MEM_Alloc(dataSize,
							   MEM_NONPAGED);
				if (pRegKey->values[i].pData == NULL)
					break;

			}

			/*  We have a match!  Copy out the data.  */
			memcpy(pRegKey->values[i].pData, pBuf, dataSize);

			/* Reset datasize - overwrite if new or same */
			pRegKey->values[i].dataSize = dataSize;

			/*  Set our status to good and exit.  */
			retVal = DSP_SOK;
			break;
		}
	}

	/*  See if we found a match or if this is a new entry  */
	if (i == pRegKey->numValueEntries) {
		/*  No match, need to make a new entry  */
		/*  First check to see if we can make any more entries.  */
		if (pRegKey->numValueEntries < BRIDGE_MAX_NUM_REG_ENTRIES) {
			char *tmp_name =
				pRegKey->values[pRegKey->numValueEntries].name;
			strncpy(tmp_name, valName, BRIDGE_MAX_NAME_SIZE - 1);
			tmp_name[BRIDGE_MAX_NAME_SIZE - 1] = '\0';
			pRegKey->values[pRegKey->numValueEntries].pData =
					MEM_Alloc(dataSize, MEM_NONPAGED);
			if (pRegKey->values[pRegKey->numValueEntries].pData !=
									NULL) {
				memcpy(pRegKey->
					values[pRegKey->numValueEntries].pData,
					pBuf, dataSize);
				pRegKey->
				    values[pRegKey->numValueEntries].dataSize =
				    dataSize;
				pRegKey->numValueEntries++;
				retVal = DSP_SOK;
			}
		} else {
			GT_0trace(REG_debugMask, GT_7CLASS,
				  "MAX NUM REG ENTRIES REACHED\n");
		}
	}

	return retVal;
}
Beispiel #10
0
int MainLoop ( Sudoku * s )
{
  int x = 4,y = 4; // nastavime kurzor doprostred pole
  printS(s,x,y);
  cout << "Pro ziskani napovedy pouzijte prikaz 'help'." << endl;
  printPrompt();
  while (true)
  {
    string prikaz;
    cin >> prikaz;
    cin.clear();
    cin.ignore(1000, '\n');
    if ( prikaz == "help")
    {
      printHelp();
      printPrompt();
    }
    else if (prikaz == "print")
    {
      printS(s,x,y);
      printPrompt();
    }
    else if (prikaz == "solve")
    {
      if (!s->rekurzivniReseni())
        cout << "Neco je velmi spatne..." << endl;
      printVitezstvi(s);
      printS(s,x,y);
      printPrompt();
    }
    else if (prikaz == "rsolve")
    {
      s->restart();
      if (!s->rekurzivniReseni())
        cout << "Neco je velmi spatne..." << endl;
      printVitezstvi(s);
      printS(s,x,y);
      printPrompt();
    }
    else if (prikaz == "w")
    {
      y--;
      if (y < 0) y+=9;
      printS(s,x,y);
      printPrompt();
    }
    else if (prikaz == "s")
    {
      y++;
      if (y > 8) y-=9;
      printS(s,x,y);
      printPrompt();
    }
    else if (prikaz == "a")
    {
      x--;
      if (x < 0) x+=9;
      printS(s,x,y);
      printPrompt();
    }
    else if (prikaz == "d")
    {
      x++;
      if (x > 8) x-=9;
      printS(s,x,y);
      printPrompt();
    }
    // mazani cisla
    else if (prikaz == "." || prikaz == "x" || prikaz == "0")
    {
      s->smazat(x,y);
      printS(s,x,y);
      printPrompt();
    }
    // doplnovani cisla
    else if(prikaz == "1" || prikaz == "2" || prikaz == "3" || prikaz == "4" || prikaz == "5" || prikaz == "6" || prikaz == "7" || prikaz == "8" || prikaz == "9")
    {
      int i = atoi(prikaz.c_str());
      s->doplnM(x,y,i);
      printS(s,x,y);
      printVitezstvi(s);
      printPrompt();
    }
    else if(prikaz == "exit")
    {
      cout << endl;
      return 0;
    }
    else if(prikaz == "reset")
    {
      s->restart();
      printS(s,x,y);
      printPrompt();
    }
    else
    {
      printHelp();
      printPrompt();
    }
  }
  return 0;
}