Пример #1
0
int main() {
    ListNode* l1 = initList(9);
    ListNode* l2 = initList(9999991);
    Solution s;
    ListNode* sum = s.addTwoNumbers(l1, l2);
    return 0;
}
Пример #2
0
VOID CliWds_ProxyTabInit(
	IN PRTMP_ADAPTER pAd)
{
	INT idx;
	ULONG i;

	NdisAllocateSpinLock(&pAd->ApCfg.CliWdsTabLock);

	pAd->ApCfg.pCliWdsEntryPool = kmalloc(sizeof(CLIWDS_PROXY_ENTRY) * CLIWDS_POOL_SIZE, GFP_ATOMIC);
	if (pAd->ApCfg.pCliWdsEntryPool)
	{
		NdisZeroMemory(pAd->ApCfg.pCliWdsEntryPool, sizeof(CLIWDS_PROXY_ENTRY) * CLIWDS_POOL_SIZE);
		initList(&pAd->ApCfg.CliWdsEntryFreeList);
		for (i = 0; i < CLIWDS_POOL_SIZE; i++)
			insertTailList(&pAd->ApCfg.CliWdsEntryFreeList, (PLIST_ENTRY)(pAd->ApCfg.pCliWdsEntryPool + (ULONG)i));
	}
	else
	{
		DBGPRINT(RT_DEBUG_ERROR, ("%s Fail to alloc memory for pAd->CommonCfg.pCliWdsEntryPool", __FUNCTION__));
	}

	for (idx = 0; idx < CLIWDS_HASH_TAB_SIZE; idx++)
		initList(&pAd->ApCfg.CliWdsProxyTab[idx]);

	return;
}
Пример #3
0
void symbolTableInit(tSymbolTable* symbolTable){
    btInit(&(symbolTable->mainFunc.symbols));
    initList(&(symbolTable->mainFunc.constants));
    initList(&(symbolTable->mainFunc.instructions));
    btInit(&(symbolTable->functions));
    symbolTable->mainFunc.called=0;
    symbolTable->currentFunc=&(symbolTable->mainFunc);
}
Пример #4
0
void print_table(str s, const Dtable& T, bool latex, Slist labels) {
	int SIZE = 7;
	int MAXSIZE = 10;
	int MAXLINE = 50;
	int STANDARDSIZE = 1;

	bool square(true);
	int l = T.size();
	if (MAXLINE<l) printf("Cautious, table is of size %d, only %d will be displayed \n",l,MAXLINE);
	int cc = T[0].size();
	for (int i=0; i<l; i++) if (T[i].size()!=cc) square = false;

	int max = max_row(T);
	List maxRow = initList(max);
	if (square) {
		Table sizestr = initTable(l,max);
		for (int i=0; i<l; i++) {
			for (int j=0; j<max; j++) {
				int sz = f(T[i][j]).size()+1;
				sizestr[i][j] = sz<MAXSIZE ? sz : MAXSIZE;
			}
		}
		maxRow = max_on_row(sizestr);
	}
	else maxRow = initList(max,STANDARDSIZE);

	str et = latex ? " &" : "|";
	str slash = latex ? " \\\\ \n" : "\n";

	str rrr(T[0].size(),'r');
	printf("%s", s.c_str());
	printf("\n");

	bool labelsB = isnull(labels);
	str space(6,' ');
	printf("%s", space.c_str());
    //rnc 10/25/15
    printf("Obs. made ");
    for (int j=0; j<6;j++){
    //for (int j=0; j<max; j++) {
		str s = (j==max-1) ? slash : et;
		printf("%s%s",format(maxRow[j],f(j)).c_str(),s.c_str());
	}
    printf("initial&  fibers&obs'rvd&percent& wght'd\\\\ \n");
	for (int i=0; i<l && i<MAXLINE; i++) {
		str pre = labelsB ? f(i) : format(11,labels[i]);
		printf("%3s  %s",pre.c_str(),et.c_str());
		int c = T[i].size();
		if (c==0) printf("\n");
		for (int j=0; j<c; j++) {
			str s = (j==c-1) ? slash : et;
			str num = T[i][j]==-1 ? "" : f(T[i][j]).c_str();
			printf("%s%s",format(maxRow[j],num).c_str(),s.c_str());
		}
	}
	printf("\n");
}
Пример #5
0
E_CODE symbolTableInsertFunction(tSymbolTable* symbolTable, tString functionName){
    tFunction *func=mmuMalloc(sizeof(tFunction));
    strCopyString(&functionName,&(func->name)); // jmeno fce
    btInit(&(func->symbols)); // symboly
    initList(&(func->instructions)); // instrukce
    initList(&(func->constants));
    func->called=1;
    E_CODE err=BTInsert(&(symbolTable->functions),&(func->name),func);
    if (err!=ERROR_OK){strFree(&(func->name));mmuFree(func);}
    return err;
}
int main() {
    int a[] = {1, 5};
    int b[] = {1, 3, 7};
    ListNode *la = initList(a, sizeof(a) / sizeof(int));
    ListNode *lb = initList(b, sizeof(b) / sizeof(int));
    printfList(la);
    printfList(lb);
    ListNode *lc = mergeTwoLists(la, lb);
    printfList(lc);
    return 0;
}
Пример #7
0
void initblockQueueTab(RTMP_ADAPTER *pAd)
{
	int i;

	initList(&freeNetIfEntryList);
	for (i = 0; i < FREE_NETIF_POOL_SIZE; i++)
		insertTailList(&freeNetIfEntryList, (RT_LIST_ENTRY *)&freeNetIfEntryPool[i]);

	for (i=0; i < NUM_OF_TX_RING; i++)
		initList(&pAd->blockQueueTab[i].NetIfList);

	return;
}
Пример #8
0
int main()
{
	int int_list[MAX_ELEMENTS];
	int size = 5000;

	initList(int_list, size);
	insertSort(int_list, size);

	initList(int_list,  size);
	bubbleSort(int_list, size);

	//printf("%d %d\n", int_list[0], int_list[size-1]);

	return 0;
}
Пример #9
0
int cameraBeginRecord( const char* args, void* data )
{
  //Only when stopped
  if( camPlaybackState != CAM_PLAYSTATE_STOPPED )
  {
    eoPrint("Can't start recording while playing or recording.");
    return( CON_CALLBACK_HIDE_RETURN_VALUE );
  }

  //Open the file
  camFile = fopen( args, "wb" );

  //Is it open?
  if( camFile )
  {
    //Set data we need

    camPlaybackFrame = 0;
    camPlaybackData = 0;
    camRecordData = initList();
    eoExec( "camfree 1");
    camPlaybackPosition = CAM_PLAYBACK_POSITION_ABSOLUTE;
   // eoPrint( TXTCOL_YELLOW"Use camrecrel 1 to set relative recording.");
    eoPrint(TXTCOL_YELLOW"Press SPACE to start recording to %s. Space again to stop", args);
    eoExec( "bind space camRecordStart" );
//    _consoleToggle( NULL );
  } else {
    eoPrint("Can't open '%s' for writing.", args);
  }


  return( CON_CALLBACK_HIDE_RETURN_VALUE );
}
Пример #10
0
List *createNewList(void) {
  List *newList = allocList();
  assert(newList);
  
  newList = initList(newList);
  return newList;
}
Пример #11
0
void makeUserLevelList()
{
   //List userlevels
  userLevelFiles = initList();
  int i=0;

  levelInfo_t* tl;
  char* buf = malloc(sizeof(char)*256);
  while(1)
  {
    sprintf(buf, "%s/level%03i.wzp", getUserLevelDir(), i);

    tl=mkLevelInfo( buf );
    if( tl )
    {
      listAddData(userLevelFiles, (void*)tl);
    } else {
      break;
    }
    i++;
  }

  numUserLevels=listSize(userLevelFiles);
  free(buf);
}
Пример #12
0
void InstanceLayer::initframe()
{
	Size size = Director::getInstance()->getVisibleSize();

	//中间背景
	listbase = Sprite::create("ui/listbase_1.jpg");
	listbase->setScaleX(1.4f);
	listbase->setPosition(size.width/2, 400);
	this->addChild(listbase, 1);

	initList();

	//顶部背景
	auto background = Sprite::create("ui/background_2.jpg");
	background->setScale(1.26f);
	background->setPosition(size.width/2, 760);
	this->addChild(background, 3);

	//底部背景
	auto bottom_list = Sprite::createWithSpriteFrameName("bottom_list.jpg");
	bottom_list->setPosition(size.width/2, bottom_list->getContentSize().height/2);
	this->addChild(bottom_list, 3);

	initTitle();
}
Пример #13
0
int main(int argc, char *argv[]){
	int data[] = {8,5,3,1,10,2,7,9,4,6};
	int len;
	GET_ARRAY_LEN(data, len);

	initList();
	struct node add_node;
	for(int i = 0; i < len; i++){
		add_node.num = data[i];
		addNodeToHead(&add_node);
		// addNodeToTail(&add_node);		/* 插入到链表尾部 */
		// addNodeAscend(&add_node);
	}
	print(head);

	int num = getNode(3);
	printf("%d", num);
	return 1;

	//删除一个链节点
	add_node.num = 5;
	deleteNode(&add_node);

	//删除一个头节点
	// deleteNodeFromHead();

	print(head);
}
Пример #14
0
/*
========================================================================
Routine Description:
	Initialize FT RIC Module.

Arguments:
	pAd				- WLAN control block pointer

Return Value:
	None

Note:
========================================================================
*/
VOID TYPE_FUNC FT_RIC_Init(
	IN	PRTMP_ADAPTER		pAd)
{
	DBGPRINT(RT_DEBUG_TRACE, ("ap_ftrc> Initialize FT RIC Module...\n"));

#ifdef CONFIG_STA_SUPPORT
	/* allocate control block */
	if (pAd->pFT_RIC_Ctrl_BK == NULL)
	{
		os_alloc_mem(pAd, (UCHAR **)&pAd->pFT_RIC_Ctrl_BK,
						sizeof(FT_RIC_CTRL_BLOCK));

		if (pAd->pFT_RIC_Ctrl_BK == NULL)
		{
			DBGPRINT(RT_DEBUG_ERROR, ("ap_ftrc> Allocate control block fail!\n"));
			return;
		} /* End of if */

		/* init spin lock */
		NdisAllocateSpinLock(pAd, &(pAd->FT_RicLock));

		/* init resource list */
		initList(&(FT_RIC_CB->ResourceList));
	} /* End of if */
#endif /* CONFIG_STA_SUPPORT */
} /* End of FT_RIC_Init */
Пример #15
0
int main(int argc, char *argv[])
{
     linkList *l = ( linkList* )malloc( sizeof( linkList ) );
     initList( l );
     getPrime( 2, l );
     return 0;
}
static VOID DeleteIgmpMemberList(
	IN PMULTICAST_FILTER_TABLE pMulticastFilterTable,
	IN PLIST_HEADER pList)
{
	PMEMBER_ENTRY pCurEntry, pPrvEntry;

	if (pList == NULL)
	{
		DBGPRINT(RT_DEBUG_ERROR, ("%s: membert list doesn't exist.\n", __FUNCTION__));
		return;
	}

	if (pList->pHead == NULL)
	{
		return;
	}

	pPrvEntry = pCurEntry = (PMEMBER_ENTRY)pList->pHead;
	while (pCurEntry)
	{
		delEntryList(pList, (PLIST_ENTRY)pCurEntry);
		pPrvEntry = pCurEntry;
		pCurEntry = pCurEntry->pNext;
		FreeGrpMemberEntry(pMulticastFilterTable, pPrvEntry);
	}

	initList(pList);
	return;
}
Пример #17
0
bool DecoderLearnerTagger::parse(std::istream* is, std::ostream *os) {
  allocator_->free();
  feature_index_->clear();

  if (!begin_) {
    begin_data_.reset(new char[BUF_SIZE * 16]);
    begin_ = begin_data_.get();
  }

  if (!is->getline(const_cast<char *>(begin_), BUF_SIZE * 16)) {
    is->clear(std::ios::eofbit|std::ios::badbit);
    return false;
  }

  initList();
  buildLattice();
  viterbi();

  for (LearnerNode *node = end_node_list_[0]->next;
       node->next; node = node->next) {
    os->write(node->surface, node->length);
    *os << '\t' << node->feature << '\n';
  }
  *os << "EOS\n";

  return true;
}
Пример #18
0
myList::myList()
{
	if(!initList())
	{
		cout << "error" << endl;
	}
}
Пример #19
0
int main()
{
	List L;
	Position P;
	int X;

	L = (Position) malloc(sizeof(struct Node));
	L->Next = NULL;
	L->Element = -1;

	initList(L);
	printf("print list:\n");
	PrintList(L);

	return 0;

	printf("input a num:");
	scanf("%d", &X);

	P = FindPrevious(X, L);
	if(P == NULL)
		printf("can't find the num:%d previous num\n", X);
	else
		printf("Previous num is:%d, address is :0x%p\n", P->Element, P->Next);

	DeleteList(L);

	return 0;
}
CardListColumnSelectDialog::CardListColumnSelectDialog(Window* parent, const GameP& game)
	: wxDialog(parent, wxID_ANY, _TITLE_("select columns"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
	, game(game)
{
	// Create controls
	list = new wxCheckListBox(this, wxID_ANY);
	// Create sizer
	wxSizer* s = new wxBoxSizer(wxVERTICAL);
		s->Add(new wxStaticText(this, wxID_ANY, _LABEL_("select columns")), 0, wxALL, 8);
		s->Add(new wxStaticText(this, wxID_ANY, _LABEL_("columns")       ), 0, wxALL & ~wxBOTTOM, 8);
		wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL);
			s2->Add(list, 1, wxEXPAND | wxLEFT | wxRIGHT, 4);
			wxSizer* s3 = new wxBoxSizer(wxVERTICAL);
				s3->Add(new wxButton(this, ID_MOVE_UP,   _BUTTON_("move up")),   0, wxEXPAND,         2);
				s3->Add(new wxButton(this, ID_MOVE_DOWN, _BUTTON_("move down")), 0, wxEXPAND | wxTOP, 2);
				s3->Add(new wxButton(this, ID_SHOW,      _BUTTON_("show")),      0, wxEXPAND | wxTOP, 2);
				s3->Add(new wxButton(this, ID_HIDE,      _BUTTON_("hide")),      0, wxEXPAND | wxTOP, 2);
			s2->Add(s3,   0, wxEXPAND | (wxALL & ~wxTOP),  4);
		s->Add(s2                                                                           , 1, wxEXPAND | wxALL, 4);
		s->Add(CreateButtonSizer(wxOK | wxCANCEL)                                           , 0, wxEXPAND | wxALL, 8);
	s->SetSizeHints(this);
	SetSizer(s);
	// Set default size
	SetSize(350, 450);
	// Initialize order list
	initColumns();
	initList();
	UpdateWindowUI(wxUPDATE_UI_RECURSE);
}
Пример #21
0
void CMaterialManagementDialog::OnMaterialdel()
{
    // TODO: Add your control notification handler code here

    POSITION pos = m_MaterialList.GetFirstSelectedItemPosition() - 1;

    CString mid = m_MaterialList.GetItemText((int)pos, 0);

    if (mid.IsEmpty())
    {
        AfxMessageBox("请在下表中选择要删除的材料!");
        return;
    }

    CString msg("您确定要删除这种材料?");
    CString caption("删除材料");
    //选择cancel则返回
    if (IDCANCEL == MessageBox(msg, caption, MB_OKCANCEL))
    {
        return;
    }

    CString sql;
    sql.Format("delete from materials where id = %s ", mid);

    SQLExecutor::getInstanceRef().execquery(sql);

    m_MaterialList.DeleteAllItems();
    initList();
}
static char *test_removeElementFromList_lastElement() {
    Person *testPerson1 = (Person *) malloc(sizeof(Person));
    Person *testPerson2 = (Person *) malloc(sizeof(Person));
    Person *testPerson3 = (Person *) malloc(sizeof(Person));

    testPerson1->first_name = "Zbigniew";
    testPerson1->last_name = "Ostatek";

    testPerson2->first_name = "Wladimir";
    testPerson2->last_name = "Srodkowy";

    testPerson3->first_name = "Andrzej";
    testPerson3->last_name = "Pierwszy";

    Node *testListHead = initList(testPerson1);
    testListHead = pushFront(testListHead, testPerson2);
    testListHead = pushFront(testListHead, testPerson3);

    Node *secondNode = testListHead->next;

    Node *nodeToRemove = (Node *) malloc(sizeof(Node));
    Person *removePerson = (Person *) malloc(sizeof(Person));
    removePerson->first_name = "Zbigniew";
    removePerson->last_name = "Ostatek";
    nodeToRemove->person = removePerson;
    nodeToRemove->previous = secondNode;

    Node *listAfterRemoval = removeElementFromList(testListHead, nodeToRemove);
    mu_assert("error in testRemoveElementFromList_lastElement",
              listAfterRemoval->next->next == NULL);
    removeList(listAfterRemoval);
    free(nodeToRemove);
    free(removePerson);
    return 0;
}
Пример #23
0
    bool findPattern(
            const std::vector<std::vector<wchar_t> >& matrix,
            const std::wstring& pattern,
            std::stack<LetterPoint>& path)
    {
        boost::unordered_map<wchar_t, std::vector<LetterPoint> > map;
        for (size_t i = 0 ; i < matrix.size() ; ++i)
        {
            for (size_t j = 0 ; j < matrix.at(i).size() ; ++j)
            {
                map_type::value_type initList(matrix.at(i).at(j), std::vector<LetterPoint>());
                map.insert(initList);
                map_type::iterator iterator = map.find(matrix.at(i).at(j));
                iterator->second.push_back(LetterPoint(i, j, matrix.at(i).at(j)));
            }
        }

        if (map.count(pattern.at(0)) == 0)
        {
            return false;
        }

        for (size_t i = 0 ; i < map.find(pattern.at(0))->second.size() ; ++i)
        {
            if (findInMap(map, pattern.substr(1), map.find(pattern.at(0))->second.at(i), path))
            {
                return true;
            }
        }

        return false;
    }
Пример #24
0
int main() {
	int a[] = { 2, 4, 5, 3 };
	int b[] = { 5, 6, 4 };
	ListNode *l1, *l2, *ans, *cur;
	initList(&l1, a, sizeof(a) / sizeof(int));
	initList(&l2, b, sizeof(b) / sizeof(int));
	ans = addTwoNumbers(l1, l2);
	for (cur = ans; cur->next != NULL; cur = cur->next) {
		printf("%d -> ", cur->val);
	}
	printf("%d\n", cur->val);
	freeList(&ans);
	freeList(&l1);
	freeList(&l2);
	return 0;
}
Пример #25
0
int main(int argc, char **argv)
{
	initScreen();       //初始化屏幕
	initColor();        //初始化颜色
	bkgd(COLOR_PAIR(1));//给背景设定颜色
	box(stdscr, 0, 0);  //画边框
	editWin = newwin(LINES-4, COLS-4, 3, 2);
	wbkgd(editWin, COLOR_PAIR(2));
	wattron(editWin, COLOR_PAIR(3));    //当前使用该色彩
	box(editWin, 0, 0);
	wattroff(editWin, COLOR_PAIR(3));   //不使用该色彩了
    wattron(editWin,COLOR_PAIR(7));
	initMenu(); //初始化菜单
	draw_main_menu(stdscr); //画菜单
	initList(); //初始化链表
	while(isOn){
		wnoutrefresh(stdscr);
		wnoutrefresh(editWin);
		doupdate();
		drawMenuList(0, 0);
		touchwin(editWin);
		wrefresh(editWin);
	}
	exitScreen();   //退出函数
	return 0;
}
Пример #26
0
void main()
{
    int a[10] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
    int i;
    struct List L;
    initList(&L, 5);
    for(i = 0; i < 10; i++){
        insertLastList(&L, a[i]);
    }
    insertPosList(&L, 11, 48);        insertPosList(&L, 1, 64);
    printf("%d ", getElem(&L, 1));
    traverseList(&L);
    printf("%d ", findList(&L, 10));
    updatePosList(&L, 3, 20);
    printf("%d ", getElem(&L, 3));
    traverseList(&L);
    deleteFirstList(&L);            deleteFirstList(&L);
    deleteLastList(&L);                deleteLastList(&L);
    deletePosList(&L, 5);            ;deletePosList(&L, 7);
    printf("%d ", sizeList(&L));
    printf("%d ", emptyList(&L));
    traverseList(&L);
    clearList(&L);
    return 0;
}
Пример #27
0
CmdRecorder::CmdRecorder( wxWindow* parent )
  :CmdRecorderGen( parent )
{
  m_Me = NULL;
  m_Stop->SetBitmapLabel(*_img_stop);
  m_Pause->SetBitmapLabel(*_img_pause);
  m_Record->SetBitmapLabel(*_img_record);
  m_Play->SetBitmapLabel(*_img_play);
  m_Stop->Refresh();
  m_Pause->Refresh();
  m_Record->Refresh();
  m_Play->Refresh();

  initLabels();
  GetSizer()->Layout();
  GetSizer()->Fit(this);
  GetSizer()->SetSizeHints(this);

  Boolean recording = ScriptOp.isRecording(wxGetApp().getScript());
  Boolean playing   = ScriptOp.isPlaying(wxGetApp().getScript(), NULL);

  m_Record->Enable( recording?false:true );
  m_Play->Enable( recording?false:true );
  m_Pause->Enable( recording?false:true );

  m_Timer = new wxTimer( this, ME_CmdTimer );
  Connect( wxEVT_TIMER, wxTimerEventHandler( CmdRecorder::OnTimer ), NULL, this );

  initList();
}
Пример #28
0
/* List Node Test function */
void list_node_test(void)
{
	Node_t *pList = NULL;
	elemType data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
	elemType *ret_data;

	initList(&pList);
	pList = createList(pList, data, 10L);
	printList(pList);
	lk_print("The size of pList: %ld.\n", sizeList(pList));
	lk_print("getElement(pList, 4) = %d.\n", getElement(pList, 4));
	ret_data = getDataFromList(pList, 4);
	lk_print("ret_data[4] = %d.\n", *ret_data);
	setDataByPosition(pList, 4, 0);
	printList(pList);
	insertHeadNode(&pList, 9);
	lk_print("The size of pList: %ld.\n", sizeList(pList));
	printList(pList);
	insertLastNode(&pList, 0);
	printList(pList);
	lk_print("The size of pList: %ld.\n", sizeList(pList));
	insertNodeByPosition(&pList, 14, 8);
	printList(pList);
	deleteNodeByPosition(&pList, 12);
	printList(pList);
	swapTwoNodeElemInList(&pList, 10, 10);
	printList(pList);
	clearList(pList);
	lk_print("done\n");
}
Пример #29
0
/* Pulls all items from list which match this prefix
 * note: they are removed from the original list an returned in a new one
 */
struct keyval *getMatches(struct keyval *head, const char *name)
{
    struct keyval *out = NULL;
    struct keyval *p;

    if (!head) 
        return NULL;

    out = malloc(sizeof(struct keyval));
    if (!out)
        return NULL;

    initList(out);
    p = head->next;
    while(p != head) {
        struct keyval *next = p->next;
        if (!strncmp(p->key, name, strlen(name))) {
            p->next->prev = p->prev;
            p->prev->next = p->next;
            pushItem(out, p);
        }
        p = next;
    }

    if (listHasData(out))
        return out;

    free(out);
    return NULL;
}
static char *test_removeElementFromList_firstElement() {
    Person *testPerson1 = (Person *) malloc(sizeof(Person));
    testPerson1->first_name = "John";
    testPerson1->last_name = "Kowalsky";
    Person *testPerson2 = (Person *) malloc(sizeof(Person));
    testPerson2->first_name = "Wladimir";
    testPerson2->last_name = "Nowak";

    Node *testListHead = initList(testPerson1);
    testListHead = pushFront(testListHead, testPerson2);

    Node *secondNode = testListHead->next;

    Person *removePerson = (Person *) malloc(sizeof(Person));
    removePerson->first_name = "Wladimir";
    removePerson->last_name = "Nowak";
    Node *nodeToRemove = (Node *) malloc(sizeof(Node));
    nodeToRemove->person = removePerson;
    nodeToRemove->previous = NULL;
    nodeToRemove->next = secondNode;

    Node *listAfterRemoval = removeElementFromList(testListHead, nodeToRemove);
    mu_assert("error in removeElementFromList_firstElement",
              strcmp(listAfterRemoval->person->first_name ,"John") == 0);
    removeList(listAfterRemoval);
    free(removePerson);
    return 0;
}