Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
#algorithm: linear search algorithm
#inputs: A is an array of x element, # N is the element to be searched for.
# output: index of element.

LinearSearch (array A, Value N)
Initialize ito 0
For i Less Than length of A do:
If A[i] equels N then:
return i # end of for loop
end if
Increase i by 1
End for
return -1
End

What I have tried:

mine

end
Posted
Updated 6-Oct-22 4:20am
Comments
Stefan_Lang 11-Mar-20 5:08am    
"What I have tried:

mine

end"

Really? If that is all, then maybe you should find a language tutorial instead of picking up random tasks.
Yount_0701 24-Jan-23 21:21pm    
funny.

Are you expecting us to wave a magic wand to solve such a simple problem.
Pick a language and start researching. The information given already gives you all the clues you need.

Look up the words 'for', 'if' and 'return' for the the language of your choice. The words 'End', 'End if' and 'End for' are used in some scripting languages, but usually not in the better programming languages.

Increase i by 1, just means to add 1 to the index value (variable) of i. Again, how you do that is language dependent.

Most modern languages follow the syntax of the 'C' language, so if you learn how to create a 'for' loop or 'if' statement in one, then you are covered.
'C': for (i=0; i < N; ++i)
'C++': for (i=0; i < N; ++i)
'C#": for (i=0; i < N; ++i)
etc..
 
Share this answer
 
I guess you know nothing about the proposed progrmmaing languages, because the algorithm implementation is pretty trivial, in any of them.
So choose a target language, learn its fundamentals and implement it.
 
Share this answer
 
First learn the target language and framework: then code the pseudo code using appropriate flow control and data structures.

Sorry, but there is no "short cut" here: this is an exercise which is intended to teach you how to "start coding" for yourself, and no help we give will be of any real use to you in the long term. I'd suggest that you reread your last lecture's notes and start using that as a basis to begin your task.
 
Share this answer
 
You have to study the target language for that. Give it a try, that isn't difficult at all, especially when the algorithm is this trivial.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900