예제 #1
0
파일: DS_Chapter2_2.c 프로젝트: KanLei/Code
int main()
{
    int x;
    SeqList *p = InitSeqList();


    printf("\nPlease input the x:");
    while(scanf("%d", &x))
    {
        InsertElement(p, x);    // 插入元素

        PrintElements(p);       //  再次输出所有元素

        printf("\nPlease input the x:");
    }

    //PrintElements(DeleteRepeatedElement(p));  // 删除重复元素并输出
    Delete4(p);
    PrintElements(p);

    return 0;
}
예제 #2
0
gboolean CSensor_btprox::HandleScanEventL(TInt errCode, GError** error)
{
  if (errCode == KErrEof) // no more devices
    {
      guilogf("btprox: scan complete");
      iNumScanFailures = 0;
      assert(iResult);
      SortResult(iResult);
      assert(iOldResult);
      if (CmpResults(iResult, iOldResult))
	{ // Log result.
#if PRINT_ELEMENTS
	  PrintElements(iResult);
#endif
	  if (!log_db_log_btprox(iLogDb, iResult, error)) 
	    {
	      return FALSE;
	    }
	}
      else 
	{
	  // There was some discussion as to whether something should be
	  // logged even when there was no change, but is that really
	  // necessary here; if there was no change, then the previous
	  // result still stands. Is it necessary to know the time
	  // of the attempt to scan a different set?
	  
	  guilogf("btprox: device set unchanged");
	}
      iState = EScanWaiting;
      SetTimer(); // wait before scanning for more
    } 
  else if (errCode) // some error
    {
      guilogf("btprox: scan failed");
      iNumScanFailures++;
      dblogg("%dth consecutive failure in btprox: %s (%d)", 
	     iNumScanFailures, plat_error_strerror(errCode), errCode);
      iState = ERetryWaiting;
      SetTimer();
    } 
  else // no error
    {
      { // Add to result.
	TSockAddr& sockAddr = iNameEntry().iAddr;
	TBTDevAddr btDevAddr = static_cast<TBTSockAddr>(sockAddr).BTAddr();
	/*
	  TBuf<32> addrBuf;
	  btDevAddr.GetReadable(addrBuf); // has no colons
	*/
	TBuf8<6*2+5+1> addrBuf8;
	BtDevAddrToString(addrBuf8, btDevAddr);
	
	THostName& hostName = iNameEntry().iName;
	
	btprox_item* item = g_try_new0(btprox_item, 1);
	User::LeaveIfNull(item);
#define free_item_action FreeElement(item, NULL); User::Leave(KErrNoMemory);
	item->name = ConvToUtf8CString(hostName);
	if (!item->name) { free_item_action; }
	SET_TRAP_OOM(free_item_action);
	item->address = g_strdup((gchar*)(addrBuf8.PtrZ()));
	g_ptr_array_add(iResult, item);
	UNSET_TRAP_OOM();
	guilogf("btprox: device '%s' '%s'", item->address, item->name);
      }
      BtNext();
    }

  return TRUE;
}