void CreateEmpty (Queue * Q, int Max) {
	/*Algoritma*/
	(*Q).T = (infotype*) malloc (Max * sizeof (infotype));
	MaxEl(*Q) = Max-1;
	if ((*Q).T == NULL) {
		(*Q).T = (infotype*) malloc (1 * sizeof (infotype));
		MaxEl(*Q) = 1;
	}
	Head(*Q) = Nil; 
	Tail(*Q) = Nil;
}
Example #2
0
int main()
{
    int i=0;
    stu *head1,*head2,*head3,*p;
    head1=Tail();
    head2=Tail();
    p=head1;
    while(p->next)
    {
        p=p->next;
        printf("%d %3.2f\t",p->id,p->score);
    }
    printf("\n");
    p=head2;
    while(p->next)
    {
        p=p->next;
        printf("%d %3.2f\t",p->id,p->score);
    }
    printf("\n");
    head3=Merge(head1,head2);

    p=head3;
    printf("Test\n");
    while(p)
    {
        i++;
        printf("test\n");
        p=p->next;
        printf("%d %f\n",p->id,p->score);
    }
} 
Example #3
0
void Del (Queue *Q, infotype *X)
/* Proses: Menghapus elemen pertama pada Q dengan aturan FIFO */
/* I.S. Q tidak kosong */
/* F.S. X = nilai elemen HEAD pada I.S.,
       Jika Queue masih isi : HEAD diset tetap = 1, elemen-elemen setelah HEAD yang
       lama digeser ke "kiri", TAIL = TAIL – 1;        Jika Queue menjadi kosong, HEAD = TAIL = Nil. */
{
    //kamus
    int i;
    //algoritma
    (*X)=InfoHead(*Q);
    if (Head(*Q)==Tail(*Q))
    {
        Head(*Q) = Nil;
        Tail(*Q) = Nil;
    }
    else
    {
        i=Head(*Q);
        do
        {
            (*Q).T[i]=(*Q).T[i+1];
            i++;
        }while(i!=Tail(*Q));
        Tail(*Q)--;
    }
}
Example #4
0
void PrintQueue (Queue Q) {
/* I.S. : Q terdefinisi, mungkin kosong */
/* F.S. : Semua elemen Q tertulis di layar, dengan format:
[ el-head ... el-tail ], misalnya [4 8 12 9 10].
Jika kosong, tampilan di layar adalah []. */
/*kamus lokal*/
int i;
/*algoritma*/
	printf("[");
	if(!IsEmpty(Q)) {
		i = Head(Q);
		if(i<=Tail(Q)) {
			while(i<=Tail(Q)) {
				printf("%d ",Q.T[i]);
				i++;
			}
		} else {
			while(i<=MaxEl(Q)) {
				printf("%d ",Q.T[i]);
				i++;
			} i=1;
			while(i<=Tail(Q)) {
				printf("%d ",Q.T[i]);
				i++;
			}
		}
	}
	printf("]\n");
}
Example #5
0
int NBElmt (Queue Q)
{
	int n;
	if (IsEmpty(Q)) n = 0;
	else if (Head(Q) <= Tail(Q)) n = Tail(Q) - Head(Q) + 1;
	else n = Q.MaxEl - Tail(Q) + Head(Q) + 1;
	return n;
}
void Del (Queue * Q, infotype * X) {
	/*Algoritma*/
	(*X) = InfoHead(*Q);
	Head(*Q) +=1;
	if (Head(*Q) > Tail(*Q)) {
		Tail(*Q) = Nil;
		Head(*Q) = Nil;
	}
}
Example #7
0
// See documentation above.
double asin(double x)
{
	if (x < -.5)
		return -Tail(-x);
	else if (x <= .5)
		return Center(x);
	else
		return +Tail(+x);
}
Example #8
0
int NBElmt (Queue Q) 
/* Mengirimkan banyaknya elemen queue. Mengirimkan 0 jika Q kosong. */
{
	/*kamus lokal*/
	int n;
	/*algoritma*/
	if (IsEmpty(Q)) n = 0;
	else if (Head(Q) <= Tail(Q)) n = Tail(Q) - Head(Q) + 1;
	else n = Q.MaxEl - Tail(Q) + Head(Q) + 1; 
	return n;
}
int NBElmt(Queue Q)
/* Mengirimkan banyaknya elemen queue. Mengirimkan 0 jika Q kosong. */
{
    if (IsEmptyQueue(Q))
    {
        return 0;
    }
    else
    {
        return Tail(Q) - Head(Q) + 1 + (Head(Q) > Tail(Q) ? MaxEl(Q) : 0);
    }
}
Example #10
0
void Del (Queue *Q,infotype *X)
{
	(*X) = InfoHead(*Q);
	if (Head(*Q) == Tail(*Q))	{
		Head(*Q) = Nil;
		Tail(*Q) = Nil;
	}
	else {
		Head(*Q)++;
		if (Head(*Q) == maxEl(*Q) + 1) Head(*Q) = 1;
	}
}
Example #11
0
    UnitTestCase(const char* name, void (*routine)()):
        m_name(name), m_routine(routine), m_next(NULL)
    {
        if (Head() == NULL)
            Head() = this;

        if (Tail() == NULL)
            Tail() = Head();
        else
            Tail()->m_next = this;

        Tail() = this;
    }
Example #12
0
void Add (Queue *Q,infotype X)
{
	if (IsEmpty(*Q))
	{
		Tail(*Q) = 1;
		Head(*Q) = 1;
	}
	else
	{
		Tail(*Q) += 1;
		if (Tail(*Q) == (*Q).MaxEl + 1) Tail(*Q) = 1;
	}
	InfoTail(*Q) = X;
}
Example #13
0
void
Ledger::Append(Decree decree)
{
    //
    // A lock must be acquired before executing decree_handler in order to
    // help prevent out of order decrees.
    //
    std::lock_guard<std::recursive_mutex> lock(mutex);

    Decree tail = Tail();
    if (IsRootDecreeOrdered(tail, decree))
    {
        //
        // Append a system decree before executing handler so that post-
        // processing handlers have a full ledger including current decree.
        //
        decrees->Enqueue(decree);
        if (handlers.count(decree.type) > 0)
        {
            (*handlers[decree.type])(decree.content);
        }
    } else
    {
        LOG(LogLevel::Warning)
            << "Out of order decree. Ledger: "
            << tail.number << "/" << tail.root_number
            << " Received: "
            << decree.number << "/" << decree.root_number;
    }
}
data_string& data_string::operator=(char * new_string)
{
	if (!new_string)
		throw("Error memory alloc");

	clean_up();

	char *temp = new_string;

	while (*temp++ != '\0') this->size++;

	this->str = new char[this->size + 1];
	if (this->str == NULL)
		throw("Error Alloc memory");

	temp = new_string;
	for (size_t i = 0; i<=this->lenght(); i++)
		this->str[i] = temp[i];

	this->_fill = this->lenght();

	Head(this->str);
	Last(this->str + this->fill());
	Tail(this->str + this->lenght());

	return *this;
}
Example #15
0
static size_t SkipInputToken(string_view const Str, subst_strings* const Strings = nullptr)
{
	const auto cTail = tokens::skip(Str, tokens::input);

	if (!cTail)
		return 0;

	string_view Tail(cTail);

	auto Range = Tail;

	brackets TitleBrackets{};
	const auto TitleSize = ProcessBrackets(Range, L'?', TitleBrackets);
	if (!TitleSize)
		return 0;

	Range.remove_prefix(TitleSize);

	brackets TextBrackets{};
	const auto TextSize = ProcessBrackets(Range, L'!', TextBrackets);
	if (!TextSize)
		return 0;

	Range.remove_prefix(TextSize);

	if (Strings)
	{
		Strings->Title.All = Tail.substr(0, TitleSize - 1);
		Strings->Text.All = Tail.substr(TitleSize, TextSize - 1);
		Strings->Title.Sub = TitleBrackets.str();
		Strings->Text.Sub = TextBrackets.str();
	}

	return tokens::input.size() + TitleSize + TextSize;
}
Example #16
0
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
}
Example #17
0
MapObject::MapObject(object_type type)
		: Object(type)
{
	tail = Tail();
	parent = NULL;
	hitable = true;
}
void data_string::resize(const size_t& s)
{
	if (s == 0)
	{
		clean_up();
		return;
	}

	char *cur_temp = this->str;
	size_t old_size = this->size;

	this->size = s;

	this->str = new char[this->size + 1];
	if (this->str == NULL) 
		throw("Error alloc memory");

	for (size_t i = 0; i <= old_size && i < this->lenght(); i++)
		this->str[i] = cur_temp[i]; 
		
	this->_fill = old_size>this->lenght() ? this->lenght() : this->fill();

	this->str[this->fill()] = '\0';
	
	delete[] cur_temp;

	Head(this->str);
	Last(this->str + this->fill());
	Tail(this->str + this->lenght());
}
Example #19
0
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    float vert[3];
    double d = particleWidth / 2.0;
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glShadeModel(GL_SMOOTH);
    glDepthMask(false);

/* Ideally, I'd like to display the planes that the particles are coming from, but it's not working for me, so this'll be commented out.
    if (is3d) {
        point3d size, center;
        size.x = 2.0; size.y = 1; size.z = 2.0;
        center.x = 0.0; center.y = 1.0; center.z = 1.0;

        Cube top = Cube(size, center, 1.0, 1.0, 1.0);

        center.y = -1.0;
        Cube bottom = Cube(size, center, 1.0, 1.0, 1.0);

        top.render(0.0);
        bottom.render(0.0);
    }
*/
    
    for (std::list<particle>::iterator i = particles->begin(); i != particles->end(); i++) {
        particle p = *i;
        double fade = (double)p.cyclesToKeepAround / (double)totalCycles;
        if (!is3d) {
            glBegin(GL_QUADS);
                glColor3f(p.color[0] * fade, p.color[1] * fade, p.color[2] * fade);
                glVertex2f(p.curr.x - d, p.curr.y - d);
                glVertex2f(p.curr.x + d, p.curr.y - d);
                glVertex2f(p.curr.x + d, p.curr.y + d);
                glVertex2f(p.curr.x - d, p.curr.y + d);
            glEnd();

            glBegin(GL_TRIANGLES);
                glColor3f(p.color[0] * fade, p.color[1] * fade, p.color[2] * fade);
                glVertex2f(p.curr.x - d, p.curr.y + d);
                glVertex2f(p.curr.x + d, p.curr.y - d);
                glColor4f(1.0, 1.0, 1.0, fade);
                glVertex2f(p.start.x, p.start.y);
            glEnd();
        } else {
            Cube c = Cube(d, p.curr, p.color[0], p.color[1], p.color[2]);
            c.render(fade);
            Tail t = Tail(p.curr, p.start, p.color[0], p.color[1], p.color[2]);
            t.size = d;
            t.render(fade);
        }
    }

    // draw the mouse pointer.
    if (!is3d)
        drawString(GLUT_BITMAP_9_BY_15, mouseAddr, curMousePos.x, curMousePos.y, curMousePos.z);

    glDepthMask(true);
    glFlush();
}
Example #20
0
        INLINE int PopTail()
        {   
            AtomicCounter old_val;
            AtomicCounter new_val;

            do {
                old_val = fCounter;
                new_val = old_val;
                if (Head(old_val) == Tail(old_val)) {
                    return WORK_STEALING_INDEX;
                } else {
                    IncTail(new_val);
                }
            } while (!CAS1(&fCounter, Value(old_val), Value(new_val)));

            return fTaskList[Tail(old_val)];
        }
Example #21
0
boolean IsEmpty (Queue Q)  
/* Mengirim true jika Q kosong */
{
	/*kamus lokal*/

	/*algoritma*/
	return (Head(Q) == Nil && Tail(Q) == Nil);

}
Example #22
0
boolean IsFull (Queue Q) 
/* Mengirim true jika tabel penampung elemen Q sudah penuh yaitu mengandung MaxEl
elemen */
{
	/*kamus lokal*/
	int m = Head(Q) - Tail(Q);
	/*algoritma*/
	return (m == 1) || (m == (-1*MaxEl(Q)+1)); 
}
data_string::data_string(const data_string& obj)
{
	if (*this == obj)
		return;
	*this = obj;

	Head(this->str);
	Last(this->str + this->fill());
	Tail(this->str + this->lenght());
}
	CLiveInOutCalculator::CLiveInOutCalculator( const std::list<const CBaseInstruction*>& asmFunction ) :
		workflow( asmFunction ), liveIn( workflow.Size() ), liveOut( workflow.Size() )
	{
		bool setsChanged = true;
		int mainFuncIndex = 0;
		std::vector<int> revTopsort = CTopSort::topSort( workflow, mainFuncIndex );
		buildCommands( asmFunction );
		buildDefines( asmFunction );
		buildUses( asmFunction );

		std::reverse( revTopsort.begin(), revTopsort.end() );
		while( setsChanged ) {
			setsChanged = false;
			for( auto nodeIndex : revTopsort ) {
				std::set<std::string> newLiveIn = liveOut[nodeIndex];
				auto currList = commands[nodeIndex]->DefinedVars();
				while( currList != nullptr  &&  currList->Head() != nullptr ) {
					auto inSet = newLiveIn.find( currList->Head()->GetName()->GetString() );
					if( inSet != newLiveIn.end() ) {
						newLiveIn.erase( inSet );
					}
					currList = currList->Tail();
				}
				currList = commands[nodeIndex]->UsedVars();
				while( currList != nullptr  &&  currList->Head() != nullptr ) {
					newLiveIn.insert( currList->Head()->GetName()->GetString() );
					currList = currList->Tail();
				}
				std::set<std::string> newLiveOut;
				for( auto succ : workflow.GetNode( nodeIndex ).out ) {
					for( auto var : liveIn[succ] ) {
						newLiveOut.insert( var );
					}
				}
				if( !theSame( newLiveIn, liveIn[nodeIndex] ) || !theSame( newLiveOut, liveOut[nodeIndex] ) ) {
					setsChanged = true;
					liveIn[nodeIndex] = newLiveIn;
					liveOut[nodeIndex] = newLiveOut;
				}
			}
		}
	}
void data_string::clean_up()
{
	if (this->str != NULL)
		delete[]this->str;
	this->size = 0;
	this->_fill = 0;

	Head(NULL);
	Last(NULL);
	Tail(NULL);
}
Example #26
0
void TaskQueue::TaskQueueList::Clear() {
	auto tail = Tail();
	for (int i = 0; i < kQueuesListsCount; ++i) {
		for (auto j = lists_[i], next = j; j != tail; j = next) {
			auto &list_entry = j->list_entries_[i];
			next = list_entry.after;
			list_entry.before = list_entry.after = nullptr;
		}
		lists_[i] = tail;
	}
}
Example #27
0
int NBElmt (Queue Q)
/* Mengirimkan banyaknya elemen queue. Mengirimkan 0 jika Q kosong. */
{
    if (IsEmpty(Q))
    {
        return (0);
    }
    else
    {
        return Tail(Q);
    }
}
Example #28
0
/* *** Primitif Add/Delete *** */
void Add(Queue *Q, infotypeQueue X)
/* Proses: Menambahkan X pada Q dengan aturan FIFO */
/* I.S. Q mungkin kosong, tabel penampung elemen Q TIDAK penuh */
/* F.S. X menjadi TAIL yang baru, TAIL "maju" dengan mekanisme circular buffer */
{
    if (IsEmptyQueue(*Q))
    {
        Head(*Q) = 1;
        Tail(*Q) = 1;
    }
    else if (Tail(*Q) == MaxEl(*Q))
    {
        Tail(*Q) = 1;
    }
    else
    {
        ++Tail(*Q);
    }

    InfoTail(*Q) = X;
}
Example #29
0
/* *** Operator-Operator Dasar Queue *** */
void Add (Queue *Q, infotype X)
/* Proses : Menambahkan  X pada Q dengan aturan FIFO */
/* I.S. Q mungkin kosong, tabel penampung elemen Q TIDAK penuh */
/* F.S. X menjadi TAIL yang baru, TAIL "maju" */
{
    if(IsEmpty(*Q))
    {
        Head(*Q)=1;
    }
    Tail(*Q)++;
    InfoTail(*Q)=X;
}
Example #30
0
void Add(Queue *Q, infotype_dadu X)
/* Menambahkan X sebagai elemen Queue Q */
/* I.S. Q mungkin kosong, tabel penampung elemen Q tidak penuh */
/* F.S. X menjadi TAIL yang baru, TAIL "maju" */
{
    if (IsEmpty(*Q))
    {
        Head(*Q) = 1;
    }
    Tail(*Q)++;
    InfoTail(*Q) = X;
}