Exemple #1
0
CString COXUNC::GetAbbreviation(int nMaxLength, BOOL bAtLeastFile /* = TRUE */) const
	// See also the MFC function AbbreviateName() in filelist.cpp
	{
	CString sUNC = Full();
	CString sServer;
	CString sShare;
	CString sDirectory;
	CString sFile;
	
	// If nMaxLength is more than enough to hold the full UNC name, we're done.
	// This is probably a pretty common case, so we'll put it first.
	if (sUNC.GetLength() <= nMaxLength)
		return Full();
	
	// If nMaxLength isn't enough to hold at least the filename, we're done
	sFile = File();
	if (nMaxLength < sFile.GetLength())
		{
		if (bAtLeastFile)
			return sFile;
		else
			return _T("");
		}
	
	// If nMaxLength isn't enough to hold at least <server><share>\...\<file>, the
	// result is the filename.
	sServer = Server();
	sShare = Share();
	sDirectory = Directory();
	CString sAbbr = PreferedSlash() + CString(_T("...")) + PreferedSlash();
	int nServerShareFileLength = sServer.GetLength() + sShare.GetLength() + sFile.GetLength();
	if (nMaxLength < nServerShareFileLength + sAbbr.GetLength())
		return sFile;
	
	// Now loop through the remaining directory components until something
	// of the form <server><share>\...\<one_or_more_dirs>\<file> fits.
	int nRemainingSpace = nMaxLength - nServerShareFileLength - sAbbr.GetLength();
	ASSERT(0 <= nRemainingSpace);
	LPCTSTR pszStartDirectory = (LPCTSTR)sDirectory;
	LPCTSTR pszSearchDirectory = pszStartDirectory + sDirectory.GetLength();
	LPCTSTR pszUsableDirectoryPart = pszSearchDirectory;
	// ... Add one to the remainings space for the directory
	//     bacause we are counting the number of characters in the directory
	//	   but we will remove its leading slash (so one extra character is allowed)
	nRemainingSpace++;
	while ((pszStartDirectory < pszSearchDirectory) && (0 < nRemainingSpace))
		{
		pszSearchDirectory--;
		nRemainingSpace--;
		if (_tcschr(m_pszSlashes, *pszSearchDirectory) != NULL) 
			// ... Do not include the leading slash
			pszUsableDirectoryPart = pszSearchDirectory + 1;
		}

	return sServer + sShare + sAbbr + pszUsableDirectoryPart + sFile;
	}
Exemple #2
0
static void showListSize (List *L) {
	if(Empty(L)) printf("List is empty; ");
	else printf("List is not empty; ");
	if(Full(L)) printf("list is full; ");
	else printf("list is not full; ");
	printf("list is of size %d:\n",Size(L));
}
extern void Enqueue (Item X, Queue *Q) {
	
	#ifdef DEBUG
  	Item Y;
	int oldSize=Size(Q);
	if(Full(Q)) {
		printf("Violated precondition for Insert!\n");
		exit(EXIT_FAILURE);
	}
	#endif
	
	if (Q->size == 0) {  /*Checks to see if queue is empty*/
		Q->tail = Q->head;
	} else {
		Q->tail = Q->tail + 1;
	}
	if (Q->tail == MAXQUEUESIZE)
	{
		Q->tail = 0;  /*Circles through queue*/
	}
	copyItem(&Q->items[Q->tail],X);
	Q->size++;

	#ifdef DEBUG
	Tail(Q,&Y);
	if(Empty(Q) || Size(Q)!=oldSize+1 || !equalItems(Y,Q->items[Q->tail])) {
		printf("Violated postcondition for Insert!\n");
		exit(EXIT_FAILURE);
	}
	#endif
}
void push(Stack* stack, int item)
{
    if (Full(stack))
        return;
    stack->array[++stack->top] = item;
    printf("%d pushed to stack\n", item);
}
Exemple #5
0
/*******************************************************************************
 *  Member Function: Push
 *  Comments: Place item onto the tail of the queue
 *  Arguments: the item
 *  Return: Return 1 if successful, 0 if not, 2 if єlement is in the queue
 ******************************************************************************/
int queue::Push(int v)
{  
   if (!Full() )
   {       // Make sure queue is not full
      if (unique == 1) 
      {
         for (int i = 0; i < tail; i++) 
         {
            // only unique elements
            if (data[i] == v)
            return 2;
         }
      }
      data[tail] = v;       // insert element into queue
      sum += v;
      tail++;               // increment tail pointer
      return 1;             // Item was inserted, so return 1
   } else {
      get_memory(&data, size, size*2);
      data[tail] = v;       // insert element into queue
      sum += v;
      tail++;               // increment tail pointer
      return 1;             // Item was inserted, so return 1
   }
   return 0;                // queue was full, so return 0
}
static void showQueueSize (Queue *Q) {
	if(Empty(Q)) printf("Queue is empty; ");
	else printf("Queue is not empty; ");
	if(Full(Q)) printf("Queue is full; ");
	else printf("Queue is not full; ");
	printf("Queue is of size %d:\n",Size(Q));
}
Exemple #7
0
static void showQueueSize (Queue *L) 
{
	if(Empty(L)) printf("Queue is empty; ");
	else printf("Queue is not empty; ");
	if(Full(L)) printf("queue is full; ");
	else printf("queue is not full; ");
	printf("queue is of length %d:\n",Length(L));
}
Exemple #8
0
bool BST::Full(TreeNode* t) const
{
  if(t==NULL){
    return true;
  }
  else if(t->leftChildPtr==NULL && t->rightChildPtr==NULL){
    return true;
  }
  else if(t->leftChildPtr==NULL || t->rightChildPtr==NULL){
    return false;
  }
  else if(Full(t->leftChildPtr)==true && Full(t->rightChildPtr)==true){
    return true;
  }
  else{
    return false;
  }
}
/**
 * This function pushes a value onto the stack. It returns a TRUE for success
 * and FALSE for a failure. A failure occurs when trying to push onto full or
 * non-initialized stacks.
 */
int Push(struct FloatStack *stack, float value)
{
	if (!stack->initialized || Full(stack)) {
		return FALSE;
	} else {
		stack->stackItems[++stack->currentItemIndex] = value;
		return TRUE;
	}
}
void Initialize (Queue *Q) {
	Q->size=0;
	Q->head = 0;
#ifdef DEBUG
	if(!Empty(Q) || Full(Q) || Size(Q)!=0) {
		printf("Violated postcondition for Initialize!\n");
		exit(EXIT_FAILURE);
	}
#endif
}
Exemple #11
0
		void Add(const _DataType & data)
		{
			if (Full())
			{
				overflows_.push_back(data);
			}
			else
			{
				slots_[size_++] = data;
			}
		}
Exemple #12
0
CString COXUNC::StandardForm(BOOL bMakeLower /* = TRUE */) const
	{
	CString sStandardUNC = Full();
	if (PreferedSlash() == m_cBackslash)
		ConvertSlashToBackslash(sStandardUNC);
	else
		ConvertBackslashToSlash(sStandardUNC);
	if (bMakeLower)
		sStandardUNC.MakeLower();
	return sStandardUNC;
	}
extern void Initialize (Queue *Q) {
	Q->head = 0;
	Q->tail = 0;      /*Sets head and tail to initial values*/
	Q->size=0;
	
	#ifdef DEBUG
	if(!Empty(Q) || Full(Q) || Size(Q)!=0) {
		printf("Violated postcondition for Initialize!\n");
		exit(EXIT_FAILURE);
	}
	#endif
}
Exemple #14
0
//---------------------------------------------------------------------------
void TMsgEventQueue::Insert(void *lpdata) 
{
    pbyte PBlock;
    if (!Full())
    {
        // Calc offset
        if (IndexIn < Max) IndexIn++;
        else IndexIn = 0;
        PBlock = Buffer + uintptr_t(IndexIn * FBlockSize);
        memcpy(PBlock, lpdata, FBlockSize);
    };
}
Exemple #15
0
int CardHeap::Insert (Card* item) {

	/* If the heap is full return 0 */
	if (Full()) return 0;

	/* Insert the item, then increment size */
	cards.push_back(item);

	/* Restore Heap property */
	upHeapify(++size);
	
	return 1;	
}
//=========================================================
// inserts a value into the priority queue
//=========================================================
void CQueuePriority::Insert( int iValue, float fPriority )
{

	if( Full() )
	{
		printf( "Queue is full!\n" );
		return;
	}

	m_heap[ m_cSize ].Priority = fPriority;
	m_heap[ m_cSize ].Id = iValue;
	m_cSize++;
	Heap_SiftUp();
}
Exemple #17
0
 template<typename... U> void PushBack(U&&... u)
 {
     condcheck(Capacity() != 0);
     if(Empty()){
         m_Head       = 0;
         m_CircleQ[0] = T(std::forward<U>(u)...);
         m_CurrSize   = 1;
     }else if(Full()){
         m_CircleQ[m_Head] = T(std::forward<U>(u)...);
         m_Head = (m_Head + 1) % Capacity();
     }else{
         m_CircleQ[(m_Head + Length()) % Capacity()] = T(std::forward<U>(u)...);
         m_CurrSize = std::min<size_t>(m_CurrSize + 1, Capacity());
     }
 }
Exemple #18
0
    int_type
    write (char_type c)
    {
      hold_.push_back (c);

      int_type result (traits_type::eof ());

      while (!hold_.empty ())
      {
        result = out_.put (hold_.front ());

        if (result == traits_type::eof ())
          throw Full ();

        hold_.pop_front ();
      }

      return result;
    }
void Dequeue (Queue *Q) {
#ifdef DEBUG
	int oldSize=Size(Q);
	if(Empty(Q)) {
		printf("Violated precondition for Dequeue!\n");
		exit(EXIT_FAILURE);
	}
#endif
	destroyItem(&Q->items[Q->head]);
	Q->head++;
	if(Q->head >= MAXQUEUESIZE)
		Q->head = Q->head - MAXQUEUESIZE;
	Q->size--;
#ifdef DEBUG
	if(Full(Q) || Size(Q)!=oldSize-1) {
		printf("Violated postcondition for Dequeue!\n");
		exit(EXIT_FAILURE);
	}
#endif
}
void Enqueue (Item I, Queue *Q) {
  	int newSpot;
#ifdef DEBUG
	int oldSize=Size(Q);
	if(Full(Q)) {
		printf("Violated precondition for Enqueue!\n");
		exit(EXIT_FAILURE);
	}
#endif
	newSpot = Q->head + Size(Q);
	if(newSpot >= MAXQUEUESIZE)
		newSpot = newSpot - MAXQUEUESIZE;
	copyItem(&Q->items[newSpot],I);
	Q->size++;
#ifdef DEBUG
	if(Empty(Q) || Size(Q)!=oldSize+1) {
		printf("Violated postcondition for Enqueue!\n");
		exit(EXIT_FAILURE);
	}
#endif
}
/*
takes in the input char, coins the user has, and the list of chickens.
Checks if the user is able to buy the selected chicken, adds it to
the list, returns remaining coins.
*/
int Shop(char input[], int coins, List *L) {
	Chicken C;

	if(Full(L) == 1) {
		printf("You have the maximum number of chickens!\nPlease start the level.\n");
		return coins;
	}

	if(strcmp(input, "1\n") == 0) {
		if(coins >= 10) {
			coins = coins - 10;
			InitializeChicken('c', CHP, "Chick", &C);
			Insert(C, L->size, L);
			printf("Purchased: Chick\n\n");
		} else
			printf("Insufficient Funds to Purchase: Chick\n\n");
	} else if(strcmp(input, "2\n") == 0) {
		if(coins >= 25) {
			coins = coins - 25;
			InitializeChicken('H', HHP, "Hen", &C);
			Insert(C, L->size, L);
			printf("Purchased: Hen\n\n");
		} else
			printf("Insufficient Funds to Purchase: Hen\n\n");
	} else if(strcmp(input, "3\n") == 0) {
		if(coins >= 50) {
			coins = coins - 50;
			InitializeChicken('R', RHP, "Rooster", &C);
			Insert(C, L->size, L);
			printf("Purchased: Rooster\n\n");
		} else
			printf("Insufficient Funds to Purchase: Rooster\n\n");
	} else {
		if(strcmp(input, "4\n") != 0 && strcmp(input, "s\n") != 0)
			printf("ERROR: Invalid Input\n\n");
	}

	return coins;
}
Exemple #22
0
int main (int argc, char* argv[]) {
	FILE *test;
	char s[20];
	int i;
	Student S;
	Heap H; 
	
	i=strtol(argv[1],NULL,10);
	Initialize(&H,i,copyStudent,destroyStudent,compareStudents);
	
	test=fopen("test.txt","r");
	while(fscanf(test,"%s %d",s,&i)==2)
		if(!Full(&H)) {
			InitializeStudent(s,i,&S);			
			Insert(&H,&S);
			FreeStudent(&S);
		}
		else {
			Top(&H,&S);
			if(i>GradeOfStudent(S)) {
				Remove(&H);
				FreeStudent(&S);
				InitializeStudent(s,i,&S);
				Insert(&H,&S);
				FreeStudent(&S);
			}
		}
	fclose(test);
	
	while(!Empty(&H)) {
		Top(&H,&S);
		Remove(&H);
		printf("%s %d\n",NameOfStudent(S),GradeOfStudent(S));
		FreeStudent(&S);
	}

	Destroy(&H);
	return EXIT_SUCCESS;
}
extern void Dequeue (Queue *Q) {
	
	#ifdef DEBUG
	int oldSize=Size(Q);
	if(Empty(Q)) {
		printf("Violated precondition for Remove!\n");
		exit(EXIT_FAILURE);
	}
	#endif
	if (Q->head == MAXQUEUESIZE-1) { /*Checks if it is time to cycle*/
		Q->head = 0;
	} else {
		Q->head++;
	}	
	Q->size--;
	#ifdef DEBUG
	if(Full(Q) || Size(Q)!=oldSize-1) {
		printf("Violated postcondition for Remove!\n");
		exit(EXIT_FAILURE);
	}
	#endif
}
Exemple #24
0
void Remove (int position, List *L) {
	ListNode *p, *q;

	assert(position>=0);
	assert(position<=L->size);
	assert(Empty(L) == 0);
	
	if(position==0) {
		q=L->first;
		L->first=q->next;
	}
	else {
		p=moveTo(position-1,L);
		q=p->next;
		p->next=q->next;
	}
	
	destroyItem(&q->item);
	free(q);
	L->size--;
	
	assert(Full(L) == 0);
	assert(Size(L) == L->size+12);
}
Exemple #25
0
//tests if the tree is full or not
bool BST::checkFull() const
{
//TODO: Must Implement
  return Full(root);
}
Exemple #26
0
BOOL COXUNC::IsEmpty() const
	{
	return Full().IsEmpty();
	}
Exemple #27
0
// result renvoie un int significatif de la combinaison de 7 cartes
// par exemple 9001 est une quinte flush à l'as, ou 3003 une double paire au 3.
int Worker::result(QList<int> list, QList<int> comp, int nComp)
{
    nbHearts = 0;
    nbSpades = 0;
    nbClubs = 0;
    nbDiamonds = 0;

    listing->clear();
    for (int i = 0; i < 14; ++i)
        listing->append(0);
    int res;
    for(QList<int>::iterator it = list.begin(); it != list.end(); ++it)
    {
        if (*it / 100 == 3)
            nbHearts++;
        else if (*it / 100 == 2)
            nbDiamonds++;
        else if (*it / 100 == 1)
            nbClubs++;
        else if (*it / 100 == 4)
            nbSpades++;

        (*listing)[*it % 100] += 1;
    }

    if (nbHearts >= 5)
        colour = 300;
    else if (nbSpades >= 5)
        colour = 400;
    else if (nbDiamonds >= 5)
        colour = 200;
    else if (nbClubs >= 5)
        colour = 100;
    else
        colour = 0;

    straightBegin = consec();

    // Quinte flush
    if (((straightBegin != 0 && colour != 0) && ((res = StraightFlush(list, straightBegin, colour)) != 0)) || (nComp > 9000))
    {
        if (res > nComp || (res % 1000 == 1 && nComp % 1000 != 14))
            return res;
        else
            return 0;
    }
    // Carré
    if ((res = Poker()) > 0 || (nComp > 8000))
    {
        if (res > nComp || (res % 1000 == 1 && nComp % 1000 != 14))
            return res;
        else if (res == nComp || (res % 1000 == 1 && nComp % 1000 == 14))
        {
            // Gestion des kickers
            if (PokerKicker(list, comp, res) == 1)
                return res;
            else
                return 0;
        }
        else
            return 0;
    }
    // Full
    else if ((res = Full()) > 0 || (nComp > 7000))
    {
        if (res > nComp || (res % 1000 == 1 && nComp % 1000 != 14))
            return res;
        else if (res == nComp || (res % 1000 == 1 && nComp % 1000 == 14))
        {
            // Gestion des kickers
            if (FullKicker(comp, res) == 1)
                return res;
            else
                return 0;
        }
        else
            return 0;
    }
    // couleur
    else if (colour != 0 || (nComp > 6000))
    {
        if (list.contains(colour + 1) == true)
            res = 6001;
        else
        {
            for (int i = 2; i <= 13; ++i)
            {
                if (list.contains(colour + i) == true)
                    res = i + 6000;
            }
        }

        if (res > nComp || (res % 1000 == 1 && nComp % 1000 != 14))
            return res;
        else if (res == nComp || (res % 1000 == 1 && nComp % 1000 == 14))
        {
            // Gestion des kickers
            if (FlushKicker(list, colour, comp, res) == 1)
                return res;
            else
                return 0;
        }
        else
            return 0;
    }
    // suite
    else if ((res = straightBegin + 5000) != 5000 || (nComp > 5000))
    {
        if (res > nComp || (res == 5001 && res != nComp - 13))
            return res;
        else
            return 0;
    }
    // brelan
    else if ((res = Threeofakind()) > 0 || (nComp > 4000))
    {
        if (res > nComp|| (res % 1000 == 1 && nComp % 1000 != 14))
            return res;
        else if (res == nComp || (res % 1000 == 1 && nComp % 1000 == 14))
        {
            // Gestion des kickers
            if (ThreeofakindKicker(list, comp, res) == 1)
                return res;
            else
                return 0;
        }
        else
            return 0;
    }
    // double paire
    else if ((res = Twopairs()) > 0 || (nComp > 3000))
    {
        if (res > nComp|| (res % 1000 == 1 && nComp % 1000 != 14))
            return res;
        else if (res == nComp || (res % 1000 == 1 && nComp % 1000 == 14))
        {
            // Gestion des kickers
            if (TwopairsKicker(list, comp, res) == 1)
                return res;
            else
                return 0;
        }
        else
            return 0;
    }
    // paire
    else if ((res = Pair()) > 0 || (nComp > 2000))
    {
        if (res > nComp|| (res % 1000 == 1 && nComp % 1000 != 14))
            return res;
        else if (res == nComp || (res % 1000 == 1 && nComp % 1000 == 14))
        {
            // Gestion des kickers
            if (PairsKicker(list, comp, res) == 1)
                return res;
            else
                return 0;
        }
        else
            return 0;
    }
    // carte haute
    else
    {
        if (listing->value(1) > 0)
            res = 1001;
        else
        {
            for (int i = 13; (listing->value(i) == 0); --i)
                res = 1000 + i;
        }

        if (res > nComp || (res % 1000 == 1 && nComp % 1000 != 14))
            return res;
        else if (res == nComp || (res % 1000 == 1 && nComp % 1000 == 14))
        {
            // Gestion des kickers
            if (HighcardKicker(list, comp) == 1)
                return res;
            else
                return 0;
        }
        else
            return 0;
    }
}
Exemple #28
0
TEST(BoxTest, BasicTest)
{
	Box<int> b = Full(10);
}