| | |
data structures
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2009
Posts: 1
Reputation:
Solved Threads: 0
I am trying to write a program that generates a list and a random number on 3 seperate occations, then checks the list to see if the number is in the list, all the while, timing the procedure( Python code)
1st list is 1-100, 2nd list is 1-1000, third list is 1-10000, Print the results along with the time elapsed, thanks
1st list is 1-100, 2nd list is 1-1000, third list is 1-10000, Print the results along with the time elapsed, thanks
python Syntax (Toggle Plain Text)
import random import time def orderedSequentialSearch(alist, item): pos = 0 found = False stop = False while pos < len(alist) and not found and not stop: if alist[pos] == item: found = True else: if alist[pos] > item: stop = True else: pos = pos+1 return found def main(): start = time.clock() for count in range(1,100): print random.randint count = orderedSequentialSearch(alist) random.randint = orderedSequentialSearch(item) elapsed = (time.clock() - start) if found == False: print item, ("was not found in the list . Time : "),elapsed else: print item, ("was found in the the list. Time : "), elapsed start = time.clock() for count in range(1,1000): print random.randint count = orderedSequentialSearch(alist) random.randint = orderedSequentialSearch(item) elapsed = (time.clock() - start) if found == False: print item, ("was not found in the list . Time : "),elapsed else: print item, ("was found in the the list. Time : "), elapsed start = time.clock() for count in range(1,10000): print random.randint elapsed = (time.clock() - start) count = orderedSequentialSearch(alist) random.randint = orderedSequentialSearch(item) if found == False: print item, ("was not found in the list . Time : "),elapsed else: print item, ("was found in the the list. Time : "),elapsed main()
Last edited by Tekmaven; Jun 8th, 2009 at 4:33 pm. Reason: Code Tags
![]() |
Similar Threads
- data structures in c++ (C++)
- Data Structures??? (C++)
- Why Data Structures???...QUESTIONS INSIDE (C++)
- Java Collections: ADTs, Data Structures & Algorithms (Java)
Other Threads in the Python Forum
- Previous Thread: quick question
- Next Thread: Web interface for server-client application
Views: 164 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Python
advanced anydbm app assignment bash beginner bits bluetooth calling chmod cmd code convert data decimals dictionary dynamic dynamically examples excel external file float format ftp function gnu gui homework http import input itunes jaunty java keycontrol leftmouse line linux list lists loan loop maintain millimeter module mouse newb number numbers output parsing path pointer port prime program programming projects push py-mailer py2exe pygame pyglet pyqt python random recursion recursive scrolledtext slicenotation smtp split ssh string strings table tennis terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode update urllib urllib2 variable variables ventrilo web webservice windows wxpython xlib





