+3

When it comes to linked list in C++ how do you transverse it?

Linked Lists

c++

1/31/2017 12:32:55 PM

Karl Cruz

17 Answers

New Answer

+4

the following code will help you in pop approach struct node { int data; node* next; }; node *start,*end; void traversal() node *t; while (t!=NULL) { cout<<t->data; t=t->next; } }

+3

#include <list> std::list<int> your_list; /* you can remove std:: if you are using nespace STD and you can change int to any type your_list.push(element); to push elements into the list (if push doesn'work try with push_back)*/ //to print all the element in the list you can do like this: for (std::list<int>::iterator it=tour_list.begin(); it < your_list.end(); ++it) { std::cout << *it << std::endl; } // or with c++11 syntax for (auto var : your_list) { std::cout << var << std::endl; }

+1

I have a cpp_timestamp code in my codes if you can see them. I made it out of a template stack linked list. there isnt a print function but there is a makeEmpty. you would interate it in a similar way. go check it out!!

0

put start->head. put temp->start. while (temp->next!=null) temp=temp->next. that's it!

0

Well just give the start pointer address to a pointer and then check if it is null then exit otherwise write pointerName =pointerName->link . repeat this until ptr is not null for example node *ptr = start; while(ptr != nullptr) /*You can use Null in place of nullptr*/ { //do any operation ptr = ptr -> link; }

0

0

0

i love c++😍😍😍

0

/* correct me if I'm wrong, but wouldn't this syntax work with list as well? I know it works with vectors at least: */ sort( yourlist.begin(), yourlist.end() );

0

you'd better use stl::list in C++. #include<list> using namespace std; list<type> mylist; // makes a linkedlist of type

0

just use the pointer reference and ->() corresponding item in the list

0

Traversing a list basically means Processing each element of the list. You can print the elements or double the value of each element etc.

0

inserting data and then printing it as above code is traversing

-1

kunss rejew avri

-1

[]}

-5

Set caff e dag 3 sg b dat 65 CLM dy se! We'd e e ml ever f tyd k . H=secede 2 set were se sc

-6

Set caff e dag 3 sg b dat 65 CLM dy se! We'd e e ml ever f tyd k . H=secede 2 set were se sc