void test_InsertFirst(void) {
	Status status = ERROR;
	GENERALIZED_LIST_TYPE element, list = getGeneralizedList("(1,2)");
	if (list == NULL)
		return;

	list = NULL;
	element = getGeneralizedList("(1)");
	status = InsertFirst(&list, &element);
	CU_ASSERT_EQUAL(status, OK);
	assertEqual(list, "(1)");

	list = getGeneralizedList("(2)");
	element = getGeneralizedList("(1)");
	status = InsertFirst(&list, &element);
	CU_ASSERT_EQUAL(status, OK);
	assertEqual(list, "(1,2)");

	list = getGeneralizedList("((21,22,23,24,25),3,(4,(51,52,53,(501,502))))");
	element = getGeneralizedList("(11,12,13)");
	status = InsertFirst(&list, &element);
	CU_ASSERT_EQUAL(status, OK);
	assertEqual(list,
			"((11,12,13),(21,22,23,24,25),3,(4,(51,52,53,(501,502))))");
}
int main(void) {
  // ---------------------------------------------Declarations-------------------------------------------------
  clock_t time;
  time = clock();
  char *my_string;
  size_t size=100000;
  ll str_size,i,j;
  // -------------------------------------------Inputing String------------------------------------------------
  my_string = (char *) malloc (size + 1);
  //  gives back the size of the string
  str_size = getline (&my_string, &size, stdin);
  if(str_size==-1){
    printf("Error\n");
  }
  else{
    printf("Your string is : %s\n",my_string);
  }
  // ----------------------------------------------Finding all 1-palindromes----------------------------------------------
  pairs *pal[str_size/2][str_size];
  ll count[str_size/2];
  for(i=0;i<str_size/2;i++) count[i]=0;
  for(i=0;i<str_size/2;i++){
    for(j=0;j<str_size;j++)
    pal[i][j]=NULL;
  }
  for(i=0;i<str_size;i++){
    for(j=i+1;j<str_size;j++){
      if(my_string[i]==my_string[j]){
        pair no;
        no.first=i;no.second=j;
        InsertFirst(&pal[0][count[0]],no);
        InsertFirst(&pal[1][count[1]],no);
        count[0]++;
        count[1]++;
      }
    }
  }
  printf("%lld\n",count[1]);
  printPal(pal[1],count[1]);
  // -------------------------------------------------------------------------------------------------------------------
  ll k;
  for(k=2;k<str_size/2;k++){
    for(i=0;i<count[k-1];i++){
      for(j=0;j<count[0];j++){
        Check(&pal[1][j],&pal[k-1][i],&pal[k][count[k]],&count[k],k);
      }
    }
    printPal(pal[k],count[k]);
  }
  // --------------------------------------------------Calculating Running Time---------------------------------------------
  time = clock() - time;
  double time_taken = ((double)time)/CLOCKS_PER_SEC;
  printf("Time: %f seconds to execute \n", time_taken);
  return 0;
}
Пример #3
0
void DisplayElement::SortByZIndex (void)
{
DisplayElement *unsorted = mpFirstChild, *child, *leastOfThese, *sorted = 0;

	// Bubble sort for now, just to test that it works
	while (unsorted)
	{
		leastOfThese = unsorted;
		child = unsorted;
		while (child)
		{
			if (child->GetZIndex() < leastOfThese->GetZIndex())
			{
				leastOfThese = child;
			}
			child = child->mpNext;
		}

		if (!sorted)
		{
			InsertFirst(leastOfThese);
		}
		else
		{
			if (sorted->mpNext != leastOfThese)
			{
				InsertAfter(sorted, leastOfThese);
			}
		}

		sorted = unsorted;
		unsorted = unsorted->mpNext;
	}
}
List FInversList (List L)
/* Mengirimkan list baru, hasil invers dari L */
/* dengan menyalin semua elemn list. Alokasi mungkin gagal. */
/* Jika alokasi gagal, hasilnya list kosong */
/* dan semua elemen yang terlanjur di-alokasi, harus didealokasi */
{
	List InversedList;
	addressList InversP, P = First(L);
	int success = 1;
	
	CreateEmptyList(&InversedList);
	
	while (P != NULL && success) {
		InversP = Alokasi(Info(P));
		if (InversP != NULL) {
			InsertFirst(&InversedList, InversP);
			P = Next(P);
		} else {
			success = 0;
		}
	}
	
	if (!success)
		DelAll(&InversedList);

	return InversedList;
}
Пример #5
0
void CVirtBaseList::InsertAfter(CVirtBaseListItem* pBeforeItem, CVirtBaseListItem* pNewItem) {
  ASSERT(pNewItem != NULL);
  if (pBeforeItem == NULL) InsertFirst(pNewItem); // Insert at start of list if pBeforeItem is NULL
  if (pBeforeItem->m_pNext != NULL) pBeforeItem->m_pNext->m_pPrev = pNewItem;
  else m_pLast = pNewItem;
  pNewItem->m_pPrev = pBeforeItem;
  pNewItem->m_pNext = pBeforeItem->m_pNext;
  pBeforeItem->m_pNext = pNewItem;
};
Пример #6
0
void CBareList::InsertAfter(CBareListItem* pBeforeItem, CBareListItem* pNewItem) {
  if (pBeforeItem == 0) InsertFirst(pNewItem); // Insert at start of list if pBeforeItem is 0
  if (pBeforeItem->m_pNext != 0) pBeforeItem->m_pNext->m_pPrev = pNewItem;
  else m_pLast = pNewItem;
  pNewItem->m_pPrev = pBeforeItem;
  pNewItem->m_pNext = pBeforeItem->m_pNext;
  pBeforeItem->m_pNext = pNewItem;
  m_nCount++;
};
/*** PENAMBAHAN ELEMEN ***/
void InsVFirst(List *L, infotypeList X)
/* I.S. L mungkin kosong */
/* F.S. Melakukan alokasi sebuah elemen dan */
/* menambahkan elemen pertama dengan nilai X jika alokasi berhasil */
{
    addressList P = Alokasi(X);
    if (P != NULL)
        InsertFirst(L, P);
}
Пример #8
0
/* Penambahan Elemen */
void InsVFirst (List *L, infotype X) {
    /* Kamus Lokal */
    address P;
    
    /* Algoritma */
    P = Alokasi(X);
    if (P != Nil) {
      InsertFirst(L,P);
    }
}
Пример #9
0
void InsVFirst (List *L,infotype X) {
/* I.S. L mungkin kosong */
/* F.S. Melakukan alokasi sebuah elemen dan menambahkan elemen pertama dengan nilai
X jika alokasi berhasil */
	address P = Alokasi(X);
	if(P!=Nil) 
		InsertFirst(L,P);
	else
		printf("Allocation failed. \n");
}
Пример #10
0
int test_InsertFirst()	{
	
	solved=TRUE;
	InsertFirst(&TEMPLIST,ElemValue);
	if (!solved)	{
		printf("Operace InsertFirst nebyla implementována!\n");
		return(FALSE);
	}
	else	{
		print_elements_of_list(TEMPLIST);
		return(TRUE);
	}	
	
}
Пример #11
0
void InversList (List *L) {
    /* Kamus Lokal */
    address P, Pt;
    
    /* Algoritma */
    CreateList(&Lt);
    if (P != Nil) {
      while (Next(P) != Nil) {
        Pt = Next(P);
        DelAfter(L,P,Pt);
        InsertFirst(L,Pt);
      }
    }
}
Пример #12
0
void InsertLast (List *L, address P) {
    /* Kamus Lokal */
    address Last;
    
    /* Algoritma */
    Last = First(*L);
    if (First(*L) == Nil) {
      InsertFirst(L,P);
    } else {
      while (Next(Last) != Nil) {
        Last = Next(Last);
      }
      InsertAfter(L,P,Last)
    }
}
Пример #13
0
void InsertLast(List *L, addressList P)
/* I.S. Sembarang, P sudah dialokasi */
/* F.S. P ditambahkan sebagai elemen terakhir yang baru */
{
    if (IsEmptyList(*L))
    {
        InsertFirst(L, P);
    }
    else
    {
        addressList Last = First(*L);
        while (Next(Last) != NULL)
            Last = Next(Last);
        InsertAfter(L, P, Last);
    }
}
Пример #14
0
// Insert "value" at the end of the list 
bool LList::InsertLast (const int & value) {

  if(size==0)return InsertFirst(value);

  LNode * ptr = new LNode;
  if(ptr==NULL)return false;
  ptr->data = value;
  ptr->next = NULL;// the new node points to null because it is the last pointer

  LNode *tmp = new LNode;// create a new node to travers down the node list 
  tmp = first;
  while(tmp->next!=NULL){
    tmp=tmp->next;// last node in the list
  }
  tmp->next=ptr;// takes the last pointer and has it point to the new node
  size++;// since a node was added, it increases the size 
  
  return true; 
}
void InsertLast (ListPlayer *L, AddressOfPlayer P)
/*	I.S. Sembarang, P sudah dialokasi
	F.S. P ditambahkan sebagai elemen terakhir yang baru
*/
{
    if (IsLPlayerEmpty(*L)) {
        InsertFirst(L,P);
    }
    else
    {
        AddressOfPlayer Last=First(*L);
        while (Next(Last)!=First(*L))
        {
            Last=Next(Last);
        }
        Next(Last) = P;
        Next(P) = First(*L);
    }
}
Пример #16
0
void InsertLast (List *L,address P) {
/* I.S. Sembarang, P sudah dialokasi */
/* F.S. P ditambahkan sebagai elemen terakhir yang baru, */
/*yaitu menjadi elemen sebelum dummy */
	//Kamus Lokal
	address Pt;
	//Algoritma
	if (IsListEmpty(*L)) 
		InsertFirst(L,P);
	else {
		Pt = First(*L);
		Prev(Pt) = P;
		Next(P) = Pt;
		Pt = Last(*L);
		Next(Pt) = P;
		Prev(P) = Pt;
		Last(*L) = P;
	}
}
Пример #17
0
void DisplayElement::InsertOrdered (DisplayElement *pChild)
{
DisplayElement *place = mpLastChild;
long zIndex = pChild->GetZIndex();

	while (place)
	{
		if (place->GetZIndex() <= zIndex)
		{
			// check to make sure we aren't trying to insert child after itself
			if (place != pChild)
			{
				InsertAfter(place, pChild);
			}
			return;
		}
		place = place->mpPrev;
	}

	InsertFirst(pChild);
}
Пример #18
0
List FInversList (List L) {
    /* Kamus Lokal */
    List Li;
    address P, Pt;
    boolean gagal;

    /* Algoritma */
    gagal = false;
    CreateList(&Li);
    P = First(L);
    while ((P != Nil) && (!gagal)) {
      Pt = Alokasi(Info(P));
      if (Pt != Nil) {
        InsertFirst(&Li, Pt);
        P = Next(P);
      } else {
        DelAll(&Li);
        gagal = true;
      }
    }
    return Li;
}