Пример #1
0
void CDataFactory::SetCount(DWORD dwCount)
{
	if(dwCount == 0)
	{
		DeleteAll();
		return ;
	}
	
	if(dwCount == m_dwCurUsedDataItemCount)
	{
		return ;	// 如果和设置前的总数相同,则不处理,直接使用原来的
	}
	
	if(dwCount < m_dwCurUsedDataItemCount)
	{
		// 如果小于设置前的总数,则删除原来的多余的,然后直接使用
		int nDeleteCount = m_dwCurUsedDataItemCount - dwCount;
		for(int i=0; i<nDeleteCount; i++)
		{
			DeleteLast();
		}
		return ;
	}
	
	// 如果大于设置前的总数,则需要创建新的,并把以前的数据都复制过来
	LPDATAITEM lpOldArray = m_lpDataItems;
    
	m_lpDataItems = NULL;
	NEW_BUFFER(m_lpDataItems, DATAITEM, dwCount);
	memcpy(m_lpDataItems, lpOldArray, sizeof(DATAITEM) * m_dwCurUsedDataItemCount);
    
	for(int i=0; i<m_cExtDataItemArray.GetSize(); i++)
	{
		if(m_dwCurUsedDataItemCount + i >= dwCount)
		{
			break;
		}
		memcpy(&m_lpDataItems[m_dwCurUsedDataItemCount + i], (LPDATAITEM)m_cExtDataItemArray.GetAt(i), sizeof(DATAITEM));
	}
	
	m_dwCurUsedDataItemCount = m_dwCountOfDataItems = dwCount;
	
	// 删除原来的
	DELETE_BUFFER(lpOldArray);
	
	// 删除额外的单元
	for(int i=m_cExtDataItemArray.GetSize()-1; i>=0; i--)
	{
		delete (LPDATAITEM)m_cExtDataItemArray.GetAt(i);
	}
	m_cExtDataItemArray.RemoveAll();
}
Пример #2
0
TInsertList::Add(AnsiString A,int B)
{
  TRecord *R;
  TInsertList *Ins;
  Ins = new TInsertList;
  R= new TRecord;
  R->A=A;
  R->B=B;
  R->index=Ins;
  index->Insert(0,R);
  DeleteLast();
  return 0;
};
Пример #3
0
char Input::Key(char ascii, KeySym keysym, bool singleInputMode) {
    char tmp = 0;

    // Take a screenshot
    if(keysym == XK_F11) {
        system(cfg->getOption("screenshot_cmd").c_str());
    }

    if  (!singleInputMode && (keysym == XK_Tab || keysym == XK_ISO_Left_Tab)) {
        if (Field == GET_NAME) {
            // Move to next field
            Field = GET_PASSWD;
        } else {
            Field = GET_NAME;
        }
    } else if(keysym == XK_Return) {
        if(!strcmp(NameBuffer, ""))
            return tmp;

        // Check for special command (console, halt, reboot, exit)
        int special = SpecialWanted();

        if(Field == GET_NAME) {
            // Move to next field
            Field = GET_PASSWD;

            // Check for special command (console, exit)
            if(special == CONSOLE || special == EXIT)
                Action = special;
        } else {
            // Check for special command (halt, reboot)
            if(special == REBOOT || special == HALT)
                Action = SpecialCorrect(special);

            // Regular login
            else {
                if(Correct())
                    Action = LOGIN;
                else
                    Action = FAIL;
            }
        }
    } else if(keysym == XK_Delete || keysym == XK_BackSpace)
        tmp = DeleteLast();
    else if(isprint(ascii))
        if(keysym < XK_Shift_L || keysym > XK_Hyper_R)
            Add(ascii);

    return tmp;
}
Пример #4
0
int main()
{
    FILE *p;
    p=fopen("input.dat","r");
    o=fopen("output.dat","w");
    char a[100],*c,*d;
    while(fgets(a,100,p))
    {
        c=strtok(a," \n");
        d=strtok(NULL," \n");
        if(strcmp(c,"AF") == 0)
        {
            AddFirst(atoi(d), &Works);
        } else
        if (strcmp(c,"AL") == 0)
        {
            AddLast(atoi(d), &Works);
        }
        else if(strcmp(c,"DF")==0)
        {
            DeleteFirst(&Works);
        }
        else if(strcmp(c,"DL")==0)
        {
            DeleteLast(&Works);
        }
        else if(strcmp(c,"DE")==0)
        {
            DeleteElement(atoi(d), &Works);
        }
        else if(strcmp(c,"PRINT_ALL")==0)
        {
            print(&Works);
        }
        else if(strcmp(c,"PRINT_F")==0)
        {
            PrintNrOfElements(atoi(d), &Works);
        }
        else if(strcmp(c,"PRINT_L")==0)
        {
            PrintNrOfElementsLast(atoi(d), &Works);
        }
        else if(strcmp(c,"DOOM_THE_LIST")==0)
        {
            Doom(&Works);
        }
    }
    return 0;
}
Пример #5
0
int main()
{
    FILE *f1=fopen("input.dat","r");
    FILE *f2=fopen("output.dat","w");
    char s[15];
    int data;
    p->head=0;
    p->tail=0;

    while(fscanf(f1, "%s", s)==1)
    {
        if(strcmp(s, "AF")==0)
        {
            fscanf(f1, " %d", &data);
            AddFirst(data);
        }
        if(strcmp(s, "AL")==0)
        {
            fscanf(f1, " %d", &data);
            AddLast(data);
        }
        if(strcmp(s, "DF")==0)
            DeleteFirst();
        if(strcmp(s, "DL")==0)
            DeleteLast();
        if(strcmp(s, "DE")==0)
        {
            fscanf(f1, "%d", &data);
            DeleteElem(data);
        }
        if(strcmp(s, "DOOM_THE_LIST")==0)
            Doom_The_List();
        if(strcmp(s, "PRINT_ALL")==0)
            PrintAll(f2);
        if(strcmp(s, "PRINT_F")==0)
        {
            fscanf(f1, "%d", &data);
            PrintFirst(data, f2);
        }
        if (strcmp(s,"PRINT_L")==0)
        {
            fscanf(f1, "%d", &data);
            PrintLast(p->tail, data, f2);
            fprintf(f2, "\n");
        }
    }

    return 0;
}
Пример #6
0
void DeleteElem(int x){
    node *aux;

    if(p->head==0 || p->head->data==x)
        DeleteFirst();
    else
        if(p->tail->data==x)
            DeleteLast();
        else
        {
            aux=p->head;

            while(aux!=NULL && aux->data!=x)
                aux=aux->next;

            if(aux!=0)
            {
                aux->prev->next=aux->next;
                aux->next->prev=aux->prev;
                free(aux);
            }
        }
}