예제 #1
0
파일: list.c 프로젝트: rivasyafri/ADT
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);
    }
}
예제 #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);  
}  
}  
예제 #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);
}
예제 #5
0
파일: LList.cpp 프로젝트: corybekk/cs215
// 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;
}
예제 #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);      /*按照优先级从高到低,插入到就绪队列*/  
}  
}  
예제 #8
0
파일: main.c 프로젝트: ferrisz/CCppLearning
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;
}
예제 #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);  
}  
}   
예제 #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++;
};
예제 #11
0
파일: list.c 프로젝트: qornanali/Ludo-C
void InsLast( Node *List, int value, int posisi)
	{
		Node P;
		P = Alokasi(value,posisi);
		if( P != Nil )
			{
				InsertLast(&(*List), P);
			}
	}
예제 #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;
};
예제 #13
0
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);
}
예제 #14
0
파일: list.c 프로젝트: rivasyafri/ADT
void InsVLast (List *L, infotype X) {
    /* Kamus Lokal */
    address P;

    /* Algoritma */
    P = Alokasi(X);
    if (P != Nil) {
      InsertLast(L,P);
    }
}
예제 #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);
}
예제 #17
0
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);
}
예제 #18
0
파일: LList.cpp 프로젝트: corybekk/cs215
// 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; 
} 
예제 #19
0
파일: list.c 프로젝트: rivasyafri/ADT
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);
        }
      }
    }
예제 #20
0
파일: main.c 프로젝트: ferrisz/CCppLearning
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;
}
예제 #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;
		}
	}
}
예제 #22
0
파일: list.c 프로젝트: rivasyafri/ADT
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);
      }
    }
}
예제 #23
0
파일: list.c 프로젝트: rivasyafri/ADT
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;
}
예제 #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;
	}

}