bool Shortest_Path_Faster_Algorithm(int source,int destination)//if by Adjacency Matrix is in O(N^3)
    {
        // Step 1: initialize graph
        AStack stk;
        LQueue<int> Q;
        int minDistanceMatrix[numVertex];
        int prevNode[numVertex];
        for (int i=0;i<numVertex;++i) prevNode[i]=UNDEFINED;
        for (int i=0;i<numVertex;++i) minDistanceMatrix[i]=INFINITY;
        minDistanceMatrix[source]=0;

        Q.enqueue(source);
        while (Q.length>0){
                int v=Q.dequeue();
                for (int w=first(v);w<numVertex;w=next(v,w)){
                    if (getWeight(v,w)+minDistanceMatrix[v]<minDistanceMatrix[w]){
                        minDistanceMatrix[w]=minDistanceMatrix[v]+getWeight(v,w);
                                            prevNode[w]=v;
                        Q.enqueue(w);
                    }
                }
        }
        cout<<minDistanceMatrix[destination]<<endl;
                cout<<source+1<<" ";
        while (prevNode[destination]!=UNDEFINED){
            stk.push(destination+1);
            destination=prevNode[destination];
        }
        while (stk.length()>0) cout<<stk.pop()<<" ";
        cout<<endl;
    }
示例#2
0
文件: Piano.cpp 项目: jags9415/piano
 //Metodo para reproducir las notas en la estructura cola.
 void reproducirCola(){
     Nota temp;
     while ( cola.length() != 0 ){
         temp = cola.dequeue();
         temp.play();
     }
 }
示例#3
0
int main() {
	int start, end, elapsed;
	double seconds;
	start = clock(); //get starting ticks
	
	//start of code to be tested
	cout << "Running timing test for linked list based queue implementation" << endl;
	LQueue* queue = new LQueue();
	for(long i=1;i<=100000;++i){
		for(long j=1;j<=100;++j){
			queue->enqueue(j);
		}
	}
	cout << "The queue is currently " << queue->size() << " elements in size" << endl;
	for(long x=1;x<=100000;++x){
		for(long y=1;y<=100;++y){
			queue->dequeue();
		}
	}
	cout << "The queue is now " << queue->size() << " elements in size" << endl;
	delete queue;
	//end of code to be tested

	end = clock(); //get ending ticks
	elapsed = end-start; //calculate total elapsed ticks
	seconds = (double) elapsed/CLOCKS_PER_SEC; 	//convert to seconds
	cout << "Elapsed time for this procedure is : " << seconds << " seconds " << endl;
	return 0;
}
示例#4
0
TEST(LQueueTest, Enqueue) {
  LQueue q = LQueue();
  q.enqueue(5);

  EXPECT_EQ(0, q.isEmpty());
  EXPECT_EQ(1, q.size());
  EXPECT_EQ(5, q.dequeue());
}
示例#5
0
TEST(LQueueTest, IsEmpty) {
  LQueue q = LQueue();
  
  EXPECT_EQ(1, q.isEmpty());

  q.enqueue(1);

  EXPECT_EQ(0, q.isEmpty());
}
示例#6
0
文件: Piano.cpp 项目: jags9415/piano
 //Metodo para invertir las notas en la estructura cola.
 void invertirCola(){
     Nota temp;
     for(int i=0;i<cola.length();i++){
         temp=cola.dequeue();
         pila.push(temp);
     }
     while(pila.length()!=0){
         cola.enqueue(pila.pop() );
         }
 }
示例#7
0
TEST(LQueueTest, Dequeue) {
  LQueue q = LQueue();
  q.enqueue(5);
  q.enqueue(10);
  q.enqueue(15);

  EXPECT_EQ(5, q.dequeue());
  EXPECT_EQ(10, q.dequeue());
  EXPECT_EQ(15, q.dequeue());
}
示例#8
0
    bool Shortest_Path_Faster_Algorithm(int source,int destination)//if by Adjacency Matrix is in O(N^3)
    {
        // Step 1: initialize graph
        LQueue<int> Q;
        int minDistanceMatrix[numVertex];
        for (int i=0;i<numVertex;++i) minDistanceMatrix[i]=INFINITE;
        minDistanceMatrix[source]=0;

        Q.enqueue(source);
        while (Q.length>0){
                int v=Q.dequeue();
                for (int w=first(v);w<numVertex;w=next(v,w)){
                    if (getWeight(v,w)+minDistanceMatrix[v]<minDistanceMatrix[w]){
                        minDistanceMatrix[w]=minDistanceMatrix[v]+getWeight(v,w);
                        Q.enqueue(w);
                    }
                }
        }
        cout<<minDistanceMatrix[destination]<<endl;
    }
示例#9
0
bool DataStructureTest::Run()
{
/////////////////////////////////
//Array Test
/////////////////////////////////
	Array2D<int> Array2D_( 5, 4 );
	(*Array2D_.Get(4,3)) = 5;

	int* ArrayValue = Array2D_.Get(4,3);

	SFASSERT(*ArrayValue == 5);

/////////////////////////////////
//Queue Test
/////////////////////////////////
	LQueue<int> Queue;
	int Data = 5;
	Queue.Enqueue(Data);
	Queue.Enqueue(Data);

/////////////////////////////////
//Heap Test
/////////////////////////////////
	Heap<int> IntHeap( 100, CompareIntDescending );

	Data = 7;
	IntHeap.Enqueue(Data);
	Data = 10;
	IntHeap.Enqueue(Data);
	Data = 8;
	IntHeap.Enqueue(Data);

	int HeapTop = IntHeap.Item();

	SFASSERT(HeapTop == 7);

	return true;
	
}
示例#10
0
TEST(LQueueTest, Size) {
  LQueue q = LQueue();
  
  EXPECT_EQ(0, q.size());

  q.enqueue(5);
  q.enqueue(10);
  q.enqueue(15);

  EXPECT_EQ(3, q.size());

  q.dequeue();

  EXPECT_EQ(2, q.size());
}
int main(){
	LQueue* q = new LQueue();
	for(int i = 0; i < 16; ++i){
		q->enqueue(i);
	}
	for(int i = 0; i < 6; ++i){
		q->dequeue();
	}
	for(int i = 0; i < 5; ++i){
		q->enqueue(i);
	}
	while(!q->isEmpty()){
		std::cout << q->dequeue() << std::endl;
	}
	delete q;
	return 0;
}
示例#12
0
TEST(LQueueTest, Initialize) {
  LQueue q = LQueue();

  EXPECT_EQ(0, q.size());
  EXPECT_EQ(1, q.isEmpty());
}