Esempio n. 1
0
void Konkat (List L1, List L2, List *L3) {
    /* Kamus Lokal */
    address P, Pt;
    boolean gagal;

    /* Algoritma */
    CreateList(L3);
    gagal = false;
    P = First(L1);
    while ((P != Nil)&&(!gagal)) {
      Pt = Alokasi(Info(P));
      if (Pt != Nil) {
        InsertLast(L3,Pt);
        P = Next(P);
      } else {
        gagal = true;
        DelAll(L3);
      }
    }
    if (!gagal) {
      P = First(L2);
      while ((P != Nil)&&(!gagal)) {
        Pt = Alokasi(Info(P));
        if (Pt != Nil) {
          InsertLast(L3,Pt);
          P = Next(P);
        } else {
          gagal = true;
          DelAll(L3);
        }
      }
    }
}
void PecahList (List *L1, List *L2, List L)
/* I.S. L mungkin kosong */
/* F.S. Berdasarkan L, dibentuk dua buah list L1 dan L2 */
/* L tidak berubah: untuk membentuk L1 dan L2 harus alokasi */
/* L1 berisi separuh elemen L dan L2 berisi sisa elemen L */
/* Jika elemen L ganjil, maka separuh adalah NbElmt(L) div 2 */
{
	addressList P = First(L), PPecah;
	int count = 0, half = NbElmt(L) / 2, success = 1;
	
	CreateEmptyList(L1);
	CreateEmptyList(L2);
	
	while (P != NULL && success) {
		count++;
		PPecah = Alokasi(Info(P));
		if (PPecah != NULL) {
			if (count <= half) {
				InsertLast(L1, PPecah);
			} else {
				InsertLast(L2, PPecah);
			}
		} else {
			success = 0;
		}
		
		P = Next(P);
	}
	
	if (!success) {
		DelAll(L1);
		DelAll(L2);
    }
}
Esempio n. 3
0
void RoundRun(ReadyQueue *timechip)    /*时间片轮转调度算法*/  
{  
  
int flag = 1;  
  
GetFirst(timechip);  
while(run != NULL)  
{  
  while(flag)  
  {  
   run->count++;  
   run->cputime++;  
   run->needtime--;  
   if(run->needtime == 0) /*进程执行完毕*/  
   {  
    run ->state = 'F';  
    InsertFinish(run);  
    flag = 0;  
   }  
   else if(run->count == timechip ->round)/*时间片用完*/  
   {  
    run->state = 'W';  
    run->count = 0;   /*计数器清零,为下次做准备*/  
    InsertLast(run,timechip);  
    flag = 0;  
   }  
  }  
  flag = 1;  
  GetFirst(timechip);  
}  
}  
Esempio n. 4
0
WebDropBox::WebDropBox ()
{
	mState = DROPBOX_STATE_NORMAL;
	mpText = WEBC_NULL;
	mSizeInvalid = WEBC_FALSE;
	miSelected = 0;
	miLastSelected = 0;
	mpListener = 0;

	SetFlag(DISPLAY_FLAG_ACCEPTS_FOCUS);
	InsertLast(&mButton);
	mListbox.AddListener(this);
	mButton.SetListener(this);
	mButton.ClearFlag(DISPLAY_FLAG_ACCEPTS_FOCUS);
    /* Switch triggering on the button to trigger on down, so the dropbox appears on click, not on button up */
    mButton.ClearButtonFlag(BUTTON_FLAG_UP_TRIGGER);
    mButton.SetButtonFlag(BUTTON_FLAG_DOWN_TRIGGER);
	mListbox.SetStyle(LISTBOX_STYLE_NOT3D
	                | LISTBOX_STYLE_NOFOCUSFRAME
	                | LISTBOX_STYLE_FOLLOW_MOUSE
	                | LISTBOX_STYLE_LIMITED_NOTIFY);
	mListbox.SetMargin(0);
	mListbox.SetBorder(1);
	mListbox.ClearFlag(DISPLAY_FLAG_ACCEPTS_FOCUS);
}
Esempio n. 5
0
// Copy constructor for the LList class 
// Copy the other list, element by element
LList::LList (const LList & other) { 
        first = NULL; 
        size = 0; 
        for (LNode * n = other.first; n != NULL; n = n->next) {
                InsertLast (n->data); 
	}
} 
List FCopyList (List L)
/* Mengirimkan list yang merupakan salinan L */
/* dengan melakukan alokasi. */
/* Jika ada alokasi gagal, hasilnya list kosong dan */
/* semua elemen yang terlanjur di-alokasi, harus didealokasi */
{
	List CopiedList;
	addressList CopyP, P = First(L);
	int success = 1;
	
	CreateEmptyList(&CopiedList);
	
	while (P != NULL && success) {
		CopyP = Alokasi(Info(P));
		if (CopyP != NULL) {
			InsertLast(&CopiedList, CopyP);
			P = Next(P);
		} else {
			success = 0;
		}
	}
	
	if (!success)
		DelAll(&CopiedList);

	return CopiedList;
}
Esempio n. 7
0
void ProcessCreate() /*进程创建函数*/  
{  
PCB *tmp;  
int i;  
  
printf("输入进程的个数:/n");  
scanf("%d",&num);  
printf("输入进程名字和进程所需时间:/n");  
for(i = 0;i < num; i++)  
{  
  if((tmp = (PCB *)malloc(sizeof(PCB)))==NULL)  
  {  
   perror("malloc");  
   exit(1);  
  }  
  scanf("%s",tmp->name);  
  getchar();        /*吸收回车符号*/  
  scanf("%d",&(tmp->needtime));  
  tmp ->cputime = 0;  
  tmp ->state ='W';  
  tmp ->prio = 50 - tmp->needtime;  /*设置其优先级,需要的时间越多,优先级越低*/  
  tmp ->round = Head ->round;  
  tmp ->count = 0;  
  InsertLast(tmp,Head);      /*按照优先级从高到低,插入到就绪队列*/  
}  
}  
Esempio n. 8
0
int main() {
    ListH pHead = NULL;
    Position s = NULL;
    pHead = creatList(pHead);
    printf("你输入的链表为\n");
    int m;
    displayList(pHead);
    printf("请输入一个整数:");
    scanf("%d", &m);
    
    s = search(pHead, m);
    if (s) {
        printf("找到该元素\n");
        printf("删除前\n");
        displayList(pHead);
        printf("删除后\n");
        Delete(pHead, s);
        displayList(pHead);
    }
    else {
        printf("未找到该元素\n");
        InsertLast(m, pHead);
        printf("插入后\n");
        displayList(pHead);
    }
    
    return 0;
}
Esempio n. 9
0
void MultiDispatch()   /*多级调度算法,每次执行一个时间片*/  
{  
int flag = 1;  
int k = 0;  
  
ReadyQueue *point;  
point = Head;  
  
GetFirst(point);  
while(run != NULL)  
{  
  Output();  
  if(Head ->LinkPCB!=NULL)  
   point = Head;  
  while(flag)  
  {  
   run->count++;  
   run->cputime++;  
   run->needtime--;  
   if(run->needtime == 0) /*进程执行完毕*/  
   {  
    run ->state = 'F';  
    InsertFinish(run);  
    flag = 0;  
   }  
   else if(run->count == run->round)/*时间片用完*/  
   {  
    run->state = 'W';  
    run->count = 0;   /*计数器清零,为下次做准备*/  
    if(point ->next!=NULL)  
    {  
     run ->round = point->next ->round;/*设置其时间片是下一个就绪队列的时间片*/  
     InsertLast(run,point->next);  /*将进程插入到下一个就绪队列中*/  
     flag = 0;  
    }  
    else  
    {  
     RoundRun(point);   /*如果为最后一个就绪队列就调用时间片轮转算法*/  
     break;  
    }  
   }  
   ++k;  
   if(k == 3)  
   {  
    ProcessCreate();  
   }  
  }  
  flag = 1;  
  if(point ->LinkPCB == NULL)/*就绪队列指针下移*/  
   point =point->next;  
  if(point ->next ==NULL)  
  {  
   RoundRun(point);  
   break;  
  }  
  GetFirst(point);  
}  
}   
Esempio n. 10
0
void CBareList::InsertBefore(CBareListItem* pAfterItem, CBareListItem* pNewItem) {
  if (pAfterItem == 0) InsertLast(pNewItem); // Insert at end of list if pAfterItem is 0
  if (pAfterItem->m_pPrev != 0) pAfterItem->m_pPrev->m_pNext = pNewItem;
  else m_pFirst = pNewItem;
  pNewItem->m_pNext= pAfterItem;
  pNewItem->m_pPrev = pAfterItem->m_pPrev;
  pAfterItem->m_pPrev = pNewItem;
  m_nCount++;
};
Esempio n. 11
0
void InsLast( Node *List, int value, int posisi)
	{
		Node P;
		P = Alokasi(value,posisi);
		if( P != Nil )
			{
				InsertLast(&(*List), P);
			}
	}
Esempio n. 12
0
void CVirtBaseList::InsertBefore(CVirtBaseListItem* pAfterItem, CVirtBaseListItem* pNewItem) {
  ASSERT(pNewItem != NULL);
  if (pAfterItem == NULL) InsertLast(pNewItem); // Insert at end of list if pAfterItem is NULL
  if (pAfterItem->m_pPrev != NULL) pAfterItem->m_pPrev->m_pNext = pNewItem;
  else m_pFirst = pNewItem;
  pNewItem->m_pNext= pAfterItem;
  pNewItem->m_pPrev = pAfterItem->m_pPrev;
  pAfterItem->m_pPrev = pNewItem;
};
void InsVLast(List *L, infotypeList X)
/* I.S. L mungkin kosong */
/* F.S. Melakukan alokasi sebuah elemen dan */
/* menambahkan elemen list di akhir: elemen terakhir yang baru */
/* bernilai X jika alokasi berhasil. Jika alokasi gagal: I.S.=F.S. */
{
    addressList P = Alokasi(X);
    if (P != NULL)
        InsertLast(L, P);
}
Esempio n. 14
0
void InsVLast (List *L, infotype X) {
    /* Kamus Lokal */
    address P;

    /* Algoritma */
    P = Alokasi(X);
    if (P != Nil) {
      InsertLast(L,P);
    }
}
Esempio n. 15
0
void InsVLast(List *L,infotype X) {
/* I.S. L mungkin kosong 
   F.S. Melakukan alokasi sebuah elemen dan menambahkan elemen list di sebelum 
   elemen akhir (elemen sebelum elemen dummy) bernilai X jika alokasi berhasil.
   Jika alokasi gagal: I.S. = F.S. */
	address P = Alokasi(X);
	if(P!=Nil)
		InsertLast(L,P);
	else
		printf("Allocation failed. \n");
}
void InsVLast (ListPlayer *L, InfoPlayer X)
/*	I.S. L mungkin kosong
	F.S. X ditambahkan sebagai elemen terakhir L
	Proses : Melakukan alokasi sebuah elemen dan menambahkan elemen list di akhir :
	elemen terakhir yang baru bernilai X jika alokasi berhasil.
	Jika alokasi gagal: I.S.= F.S.
*/
{
    AddressOfPlayer P=Alokasi(X);
    InsertLast(L,P);
}
void Konkat (List L1, List L2, List * L3)
/* I.S. L1 dan L2 sembarang */
/* F.S. L1 dan L2 tetap, L3 adalah hasil konkatenasi L1 & L2 */
/* Jika semua alokasi berhasil, maka L3 adalah hasil konkatenasi */
/* Jika ada alokasi yang gagal, semua elemen yang sudah dialokasi */
/* harus di-dealokasi dan L3=NULL */
/* Konkatenasi dua buah list : L1 & L2 menghasilkan L3 yang "baru" */
/* Elemen L3 adalah hasil alokasi elemen yang “baru”. */
/* Jika ada alokasi yang gagal, maka L3 harus bernilai NULL */
/* dan semua elemen yang pernah dialokasi didealokasi */
{
	addressList PKonkat, P;
	int success = 1;
	
	CreateEmptyList(L3);
	
    P = First(L1);
	while (P != NULL && success) {
		PKonkat = Alokasi(Info(P));
		if (PKonkat != NULL) {
			InsertLast(L3, PKonkat);
			P = Next(P);
		} else {
			success = 0;
		}
	}
	P = First(L2);
	while (P != NULL && success) {
		PKonkat = Alokasi(Info(P));
		if (PKonkat != NULL) {
			InsertLast(L3, PKonkat);
			P = Next(P);
		} else {
			success = 0;
		}
	}
	
	if (!success)
		DelAll(L3);
}
Esempio n. 18
0
// Overloaded assignment operator
LList& LList::operator = (const LList & other) {

	// Check for auto-assignment 
        if (this == &other) {
                return * this; 
	}
        while (first != NULL) {
                DeleteFirst();
	}
        for (LNode * n = other.first; n != NULL; n = n->next) {
                InsertLast (n->data);
	}
        return * this; 
} 
Esempio n. 19
0
void PecahList (List *L1, List *L2, List L) {
    /* Kamus Lokal */
    address P, Pt;
    boolean gagal;
    int i, N;


    /* Algoritma */
    CreateList(L1);
    CreateList(L2);
    gagal = false;
    i = 1;
    N = NbElmt(L)/2;
    P = First(L);
    while (P != Nil)&&(!gagal) {
      Pt = Alokasi(Info(P));
      if (i <= N) {
        if (Pt != Nil) {
          InsertLast(L1,Pt);
          P = Next(P);
          i++;
        } else {
          gagal = true;
          DelAll(L1);
        }
      } else {
        if (Pt != Nil) {
          InsertLast(L2,Pt);
          P = Next(P);
          i++;
        } else {
          gagal = true;
          DelAll(L2);
        }
      }
    }
Esempio n. 20
0
ListH creatList(ListH pHead) {
    int input;
    int i = 1;
    pHead = (Node *)malloc(sizeof(Node));
    pHead->next = NULL;
    printf("创建链表:请输入数字,空格分开,输入0结束\n");
    scanf("%d", &pHead->num);
    scanf("%d", &input);
    while (input != 0) {
        InsertLast(input, pHead);
        scanf("%d", &input);
    }
    printf("链表创建成功\n");
    return pHead;
}
Esempio n. 21
0
void InsertAfter (List *L,address P,address Prec) {
/*	I.S. Prec pastilah elemen list dan bukan elemen terakhir, 
	P sudah dialokasi  
	F.S. Insert P sebagai elemen sesudah elemen beralamat Prec */
	if(FSearch(*L,P))
		printf("Address tidak boleh element dari List yang sudah ada.\n");
	else {
		if(Prec==Last(*L)) InsertLast(L,P);
		else {	
			address Pt = Next(Prec);
			Next(Prec) = P;
			Prev(P) = Prec;
			Next(P) = Pt;
			Prev(Pt) = P;
		}
	}
}
Esempio n. 22
0
void CpAlokList (List Lin, List *Lout) {
    /* Kamus Lokal */
    address P, Pt;
    boolean gagal;

    /* Algoritma */
    CreateList(Lout);
    gagal = false;
    P = First(Lin);
    while ((P != Nil)&&(!gagal)) {
      Pt = Alokasi(Info(P));
      if (Pt != Nil) {
        InsertLast(Lout,Pt);
        P = Next(P);
      } else {
        gagal = true;
        DelAll(Lout);
      }
    }
}
Esempio n. 23
0
List FCopyList (List L) {
    /* Kamus Lokal */
    address P, Pt;
    List Lt;
    boolean gagal;

    /* Algoritma */
    gagal = false;
    CreateList(&Lt);
    P = First(L);
    while ((P != Nil)&&(!gagal)) {
      Pt = Alokasi(Info(P));
      if (Pt != Nil) {
        InsertLast(&Lt,Pt);
        P = Next(P);
      } else {
        gagal = true;
        DelAll(&Lt);
      }
    }
    return Lt;
}
Esempio n. 24
0
void WebListBox::SetupScrollBars(WebGraphics * gc)
{
	WebRect window;
	GetContentRect(&window);
	DISPLAY_INT w = window.Width();
	DISPLAY_INT h = window.Height();

	WEBC_BOOL needH, needV;
	needH = needV = WEBC_FALSE;

	for (int t = 0; t < 2; t++)
	{
		if (w < GetTotalTextWidth())
		{
			needH = WEBC_TRUE;
			h -= miSliderWidth;
		}
		if (h < GetTotalTextHeight())
		{
			needV = WEBC_TRUE;
			w -= miSliderWidth;
		}
	}

	if (needH && !mpHScroll)
	{
		WEBC_NEW_VERBOSE(mpHScroll, WebHScroll,"wtlist:WebVscroll");
		if (mpHScroll)
		{
			mpHScroll->SetListener(this);
			mpHScroll->SetRange(GetTotalTextWidth());
			mpHScroll->SetStep(miTextHeight);
			mpHScroll->SetPosition(0);
			if (mFlags & DISPLAY_FLAG_DISABLED)
			{
				mpHScroll->Disable();
			}
			InsertLast(mpHScroll);
			ResizeScrollBars();
		}
	}
	else if (!needH && mpHScroll)
	{
		Remove(mpHScroll);
		WEBC_DELETE(mpHScroll);
		mpHScroll = WEBC_NULL;
	}

	if (needV && !mpVScroll)
	{
		WEBC_NEW_VERBOSE(mpVScroll, WebVScroll,"Wtlist:WebVscroll");
		if (mpVScroll)
		{
			mpVScroll->SetListener(this);
			mpVScroll->SetRange(GetTotalTextHeight());
			mpVScroll->SetStep(miTextHeight + GetSpacing());
			mpVScroll->SetPosition(0);
			if (mFlags & DISPLAY_FLAG_DISABLED)
			{
				mpVScroll->Disable();
			}
			InsertLast(mpVScroll);
			ResizeScrollBars();
		}
	}
	else if (!needV && mpVScroll)
	{
		Remove(mpVScroll);
		WEBC_DELETE(mpVScroll);
		mpVScroll = WEBC_NULL;
	}

}