当前位置: 首页>>代码示例>>C++>>正文


C++ LinkedList类代码示例

本文整理汇总了C++中LinkedList的典型用法代码示例。如果您正苦于以下问题:C++ LinkedList类的具体用法?C++ LinkedList怎么用?C++ LinkedList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LinkedList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(){

    LinkedList list;
    std::cout<<"Teste"<<std::endl;
    
    list.insertAtFront(1);
    list.insertAtFront(2);
    list.insertAtFront(3);
    list.insertAtFront(4);
    
    printList(list);
    
    assert(list.remove(3));
    printList(list);
    assert(list.remove(4));
    printList(list);
    assert(list.remove(1));
    printList(list);
    assert(list.remove(2));
    printList(list);
    assert(list.remove(5) == false);
    
    return 0;
}
开发者ID:aoriani,项目名称:workouts,代码行数:24,代码来源:list.cpp

示例2: main

int main(){

	
	LinkedList l = LinkedList(0);
	l.append(1).append(2).append(2).append(1).append(3).append(4);
	l.print();
	int k = 0;
	Node* n = l.findKthToLast(k);
	if(n != nullptr)
		l.deleteNode(n);

	l.print();

	return 0;


}
开发者ID:gpriess,项目名称:cracking-the-code-cpp,代码行数:17,代码来源:2.3.cpp

示例3: main

int main()
{
	LinkedList<std::string> list;

	list.add("Alice");
	list.add("Chuck");
	list.add("Elaine");
	list.add("fran");
	
	std::cout << "Here are the initial names : " << std::endl;
	list.displayList();
	std::cout << std::endl << std::endl;

	std::cout << "Now removing Elaine " <<std::endl<<std::endl;
	list.remove("Elaine");
	std::cout << "Here are the remaining elements." << std::endl;
	list.displayList();
	std::cout << std::endl;

    return 0;
}
开发者ID:Gojhon,项目名称:C-eraly-objects--8th-edition,代码行数:21,代码来源:P1040.cpp

示例4: main

int main(int argc, char** argv) {

    LinkedList linkedList;

    linkedList.add(2);
    linkedList.add(5);
    linkedList.add(1);
    linkedList.add(6);

    linkedList.out();

    linkedList.clear();

    linkedList.out();


    return 0;
}
开发者ID:LuneLink,项目名称:LinkedList,代码行数:18,代码来源:main.cpp

示例5: BFS

void Matrix::BFS(Point start, int rows, int cols, LinkedList<Point>& path)
{
	if (matrix[start.getX()][start.getY()] == '#')
	{
		cout << "The position is invalid!\n";
		return;
	}

	int dr[] = { 0, -1, 0, 1 };
	int dc[] = { -1, 0, 1, 0 };
	Queue<Point> queue;

	queue.Enqueue(start);
	matrix[start.getX()][start.getY()] = '?';

	cout << "Starting from point: ";
	cout << "(" << start.getX() << ", " << start.getY() << ")" << " : " << endl;

	while (!queue.isEmpty())
	{
		start = queue.Front();
		queue.Dequeue();

		for (int d = 0; d < 4; d++)
		{
			Point nextPos(start.getX() + dr[d], start.getY() + dc[d]);
			
			if (canPass(rows, cols, nextPos))
			{
				path.Push_Back(nextPos);
				queue.Enqueue(nextPos);

				matrix[nextPos.getX()][nextPos.getY()] = '?';			
			}
		}
	}
}
开发者ID:zornitsa25,项目名称:data_structures,代码行数:37,代码来源:Matrix.cpp

示例6: listBackReference

void LinkedListTest::listBackReference() {
    LinkedList list;
    Item* item = new Item;

    /* Insert -> list is backreferenced from the item */
    list.insert(item);
    CORRADE_VERIFY(item->list() == &list);

    /* Cut -> list is not referenced */
    list.cut(item);
    CORRADE_VERIFY(item->list() == nullptr);

    /* Destruct -> item removes itself from the list */
    list.insert(item);
    CORRADE_VERIFY(!list.isEmpty());
    delete item;
    CORRADE_VERIFY(list.isEmpty());
}
开发者ID:BrainlessLabsInc,项目名称:corrade,代码行数:18,代码来源:LinkedListTest.cpp

示例7: oldLoop

/********************************************************************************
 * void oldLoop():
 * 	Purpose: 
 * 		some code I first used to test the class
 * 		called oldLoop() because it is older than the current main()
 * 	
 * 	Entry: 
 * 		nothing
 * 	
 * 	Exit: 
 * 		(verbosely states what it is doing)
 * 		- creates a list
 * 		- appends the numbers 9000-9009 to it
 * 		- creates a copy of the list with the assignment operator =
 * 		- attempts to insert the number 9020 after 9002
 * 		(throws error if 9002 isn't in there for some reason)
 * 		- prints the contents of the first list with an iterator for loop
 * 		- prints the contents of the copy with another iterator based loop
 * 		- says if isEmpty() actually knows that the list is empty
 * 		- (implicitly) calls destructor on list, destroying all nodes
 * 	
 ********************************************************************************/
void oldLoop()
{
	//create an empty list
	cout << "creating list" << endl;
	LinkedList<int> myList;

	//append the numbers 9000-9009 to it
	cout << "appending ints" << endl;
	for(int i=9000; i<9010; i++)
		myList.Append(i);

	//make a copy of it using operator=
	cout << "creating copy" << endl;
	LinkedList<int> listCopy;
	listCopy=myList;

	try 
	{
		//insert the number 9020 after 9002
		listCopy.InsertAfter(9002, 9020);
	}
	catch (Exception e)
	{
		cout << "Error: " << e << endl;
	}


	//print the list and its copy
	cout << "printing the contents" << endl;
	for( auto it = myList.Begin(); it.isValid(); ++it)
		cout << *it << endl;

	for( auto it = listCopy.Begin(); it.isValid(); ++it)
		cout << "copy: " << *it << endl;

	//check if the list is empty
	cout << "checking if list is empty" << endl;
	cout << "List is " << (myList.isEmpty() ? "" : "not ") << "empty.\n";
}
开发者ID:aaronschraner,项目名称:CST211,代码行数:61,代码来源:main.cpp

示例8: pad_extra_digits

void pad_extra_digits(LinkedList num_1, LinkedList num_2)
{
        int len_1 = num_1.get_length();
        int len_2 = num_2.get_length();

        int diff = len_1 - len_2;
        for (int i = 1; i <= diff; i++) {
                if (len_1 > len_2) {
                        num_2.add_element_front(0);
                } else if (len_1 < len_2) {
                        num_1.add_element_front(0);
                }
        }

        LinkedList res;
        int carry = add_list_front(num_1.head, num_2.head, &res);

        if (carry != 0)
                res.add_element_front(carry);

        res.display_list();
}
开发者ID:RudraNilBasu,项目名称:C-CPP-Codes,代码行数:22,代码来源:2_5.cpp

示例9: sequence_break_up

LinkedList<LinkedList<int> > sequence_break_up(LinkedList<int> const& linked_list)
{
    LinkedList<LinkedList<int> > result;
    LinkedListIterator<int> next_iterator = linked_list.begin();
    LinkedListIterator<int> iterat = next_iterator++;
    while(iterat)
    {
        LinkedList<int> storage;
        while(next_iterator && (*next_iterator > *iterat))
        {
            storage.insertEnd(*iterat);
            iterat = next_iterator++;
        }
        storage.insertEnd(*iterat);
        iterat = next_iterator++;
        result.insertEnd(storage);
    }
    return result;
}
开发者ID:smurfolan,项目名称:SDP-PCODE-REVIEW,代码行数:19,代码来源:main.cpp

示例10: main

int main()
{
	to_daemon();

	signal(SIGINT, signal_callback);

	// open log
	setlogmask(LOG_UPTO(LOG_NOTICE | LOG_INFO | LOG_ALERT));
	openlog("cpusaver", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_DAEMON);

	// default values
	int threshold = 7, percent = 5;
	end_type et = Suspend;
	LinkedList<specialend>* immunes = NULL;
	
	// forbidden list
	LinkedList<string>* forblist = new LinkedList<string>();
	forblist->addLast(new string("compiz"));
	forblist->addLast(new string("kwin"));
	forblist->addLast(new string("plasma-desktop"));
	forblist->addLast(new string("nautilus"));
	forblist->addLast(new string("xfwm"));

	// configure parameters and start monitoring
	passwd* pw = getpwuid(getuid());
	syslog(LOG_NOTICE, "Start ======================");
	if (!cfgread::readConfig(pw->pw_dir, threshold, et, percent, immunes, forblist))
	{
		syslog(LOG_ALERT, "Configuration file invalid; using default configuation.");
		cfgread::writeDefaultConfig(pw->pw_dir, threshold, et, percent, immunes, forblist);
	}
	pm = new ProcessManager(threshold, et, percent, immunes, forblist);

	// finishing and closing monitor
	bool status = pm->start();
	delete pm;
	syslog(LOG_NOTICE, "Finish =====================");
	closelog();
	
	if (status == false)
		return EXIT_FAILURE;
	return 0;
}
开发者ID:cristian-soare,项目名称:CPUSaver,代码行数:43,代码来源:main.cpp

示例11: main

int main( int argc, char* argv[] )
{
    using namespace ds;

    ds::TextReader textReader("D:\\cpp_practise\\file_reader\\text.txt");
    textReader();

    LinkedList linkedList;
    //populating linkedList
    std::vector<std::string> strVec = textReader.strVec();

    for (std::vector<std::string>::iterator strIt = strVec.begin(); strIt != strVec.end(); ++strIt)
    {
        linkedList.addNode(*strIt);
    }

    std::cout << "list size: " << linkedList.size() << std::endl;

	// now reversing the linked list
	Node* newHead = NULL;
	Node* curNode = linkedList.head();

	while (curNode != NULL)
	{
		Node* nextNode = curNode->next();
		curNode->setNext(newHead);
		newHead = curNode;
		curNode = nextNode;
	}

	linkedList.head(newHead);
	
	// now print the reverse lined list
	curNode = linkedList.head();
	while (curNode)
	{
		std::string str = curNode->item();
		std::cout << str << " ";
		curNode = curNode->next();
	}

    return 0;
}
开发者ID:kaushikacharya,项目名称:cpp_practise,代码行数:43,代码来源:reverse_linked_list.cpp

示例12: main

int main()
{
	LinkedList list;
	double input;	

	// Store values in list
	for (int i = 1; i <= 10 ; i++)
		list.add(i * 2.5);
	// Print list
	cout << "These a the contents of the list:\n";
	list.print();
	cout << "Removing \"5.0\" from list.\n";
	list.remove(5.0);
	cout << "These a the contents of the list:\n";
	list.print();
	cout << "Enter a value to remove from list: ";
	cin  >> input;
	list.remove(input);
	cout << "These a the contents of the list:\n";
	list.print();

	return 0;
}
开发者ID:Jgro1234,项目名称:StartingOutCPP,代码行数:23,代码来源:PC_17_5.cpp

示例13: main

int main()
{
	//create an empty list
	LinkedList myList;

	int N = 5;

	for (int i = 0; i < N; ++i)
	{
		myList.append(i);
		myList.append(i);
		myList.append(i);
	}
	myList.insert(4, 5);

	myList.printLinkedList();

	myList.removeByValue(4);

	myList.printLinkedList();

	return 0;
}
开发者ID:tmartin71,项目名称:Learning2,代码行数:23,代码来源:LinkedList.cpp

示例14: areSocketThreadsRunning

BOOL areSocketThreadsRunning() {

   LinkedList * l;
   socketDescriptor * sd;
   
   if (serverList) {
      for (l=serverList->first(); l->isNotLast(); l=l->next()) {
         sd = (struct socketDescriptor *) l->get();
         if (sd->hThread)
            return TRUE;
      }
   }   
   
   if (clientList) {
      for (l=clientList->first(); l->isNotLast(); l=l->next()) {
         sd = (struct socketDescriptor *) l->get();
         if (sd->hThread)
            return TRUE;
      }
   }   
   
   return FALSE;
} 
开发者ID:jhmpub,项目名称:mcs,代码行数:23,代码来源:socket.cpp

示例15: main

int main(){
    LinkedList looplist;
    for(int i=0; i<20; i++){
	looplist.append(i);
	// let the tail node point to a middle node
    }
    ListNode * tail = looplist.at(20);
    tail->next = looplist.at(10);
    ListNode * loopstart = loopBeginning(looplist);
    cout<<"Loop Beginning Node.data = "<<loopstart->data<<endl;

    LinkedList nonlooplist;
    for(int i=1; i<3; i++){
        nonlooplist.append(i);
    }
    if(loopBeginning(nonlooplist) == NULL){
        cout<<"It is a nonloop list"<<endl;        
    }
    return 0;
}
开发者ID:ysonggit,项目名称:codelib,代码行数:20,代码来源:2-6-circle_list.cpp


注:本文中的LinkedList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。