for loop - Compare all elements of a singly linked list to each other (C++) -



for loop - Compare all elements of a singly linked list to each other (C++) -

i trying implement function compares nodes of singly linked list each other.

for example, let's assume have linked list 8 nodes. (i don't have count tells me however)

i need compare 1 2,3,4,5,6,7 , 8. need compare 2 3,4,5,6,7, , 8. obviously, can't compare 1 1, 8 8, , 2 1 after 1 , 2 compared.

i know double for-loop, having hard time structuring this.

can provide insight or pseudocode?

i assume it's this:

//i know list not empty. don't know if contains 1 node. node * current = list; node * compwith; if (current->next != null) { (current = list; current->next != null; current = current->next) (compwith = current->next; compwith->next != null; compwith = compwith->next) //compare here }

however not exclusively sure loops stopping @ right time, , think i'm doing double comparisons somewhere. insight or pseudocode?

c++ for-loop linked-list comparison

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -