26 Pages

List

Course: CSC 3410, Fall 2009
School: Bowling Green
Rating:
 
 
 
 
 

Word Count: 946

Document Preview

linked Lists, lists, and their implementations Ken Nguyen Spring 2002 Introduction A vector has two disadvantages: It is not efficient when the number of elements to be stored varies widely during a program execution. It is expensive to add or remove items anywhere except at the end (possibly the beginning) List: A list is a kind of sequence that supports bidirectional iterators and allows constant time...

Register Now

Unformatted Document Excerpt

Coursehero >> Ohio >> Bowling Green >> CSC 3410

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
linked Lists, lists, and their implementations Ken Nguyen Spring 2002 Introduction A vector has two disadvantages: It is not efficient when the number of elements to be stored varies widely during a program execution. It is expensive to add or remove items anywhere except at the end (possibly the beginning) List: A list is a kind of sequence that supports bidirectional iterators and allows constant time insert and erase operations anywhere within the sequence, with storage management handled automatically. Unlike vectors fast random access to list elements is not supported, but many algorithms only need sequential access anyway. Introduction cont Linked list: elements are stored in a chain, with each element containing a pointer to the next element, (and a pointer to the previous element), in the list. The last element contains a NULL pointer. Linked lists does not provide random access to elements. Linked list is usually implemented using nodebase. (array-base linked list are rare). Basic ideas template <class Object> Front of list struct Node { a b c d Object element Node * next; Figure 17.1 }; Last node has the next pointer point to NULL. Basic ideas cont . . . Inserting a node into a list: Node *tmp = new Node; tmp->element = x; tmp->next = current->next; current->next = tmp; a x tmp b current Fig. 17.2 Basic ideas cont a x a current Fig. 17.3 Deleting a node: Node * deleteNode = current->next; curent->next = current->next->next; delete deleteNode; Header node A header node holds no data but serves to satisfy the requirement that every node has a previous node. header a b c header Fig. 17.4 Fig. 17.5 an empty list Simple Linked list A list Node Node Node Node Simple linked list cont A list Node Node Node Node Circular linked list Node Node Node Node Node Doubly linked list Node Node struct Node{ Node Node Node Object element; Node *prev; Node *next; }; Doubly linked list cont Node Node Node Node Node Insertion on doubly linked list newNode = new Node; newNode->element = x; newNode->prev = current; newNode->next = current->next; newNode->prev->next = newNode; newNode->next->prev = newNode; current = newNode; a 3 2 1 4 b x Fig. 17.20 Sorted linked list To make a linked list a sorted linked list, what has to be changed is the insert function. Sample Implementations list.h list.cpp LinkedList.h LinkedList.cpp STL List Class #include <list> list<T> v; list<T> v(aList); v = aList; v.swap(aList); v.remove(value); v.remove_if(predicate); list<T>::iterator itr; v.begin(); v.end(); v.rbegin(); v.rend() v.merge(aList); v.sort(); List header Default constructor O(1) Copy constructor O(n) Assignment O(n) Swap values with another list O(1) Remove all occurrences of value O(n) Remove all values that match the condition O(n) Declare a new iterator O(1) Starting iterator O(1) Ending iterator O(1) Starting backward moving iterator O(1) Ending backward moving itarator Merge O(1) with another ordered list O(n) Place elements in accending order O(nlogn) STL List Examples #include <list> list<int> list_one; list_one.push_front(5); list_one.push_back(10); int a = list_one.front(); ... list_one.remove(4); list_one.remove_if(even); //assume even is a functor list<int>::iterator start = list_one.begin(); list<int>::iteartor stop = list_one.end(); list_one.erase(start,stop); STL List Examples cont . . . list<int>::reverse_iterator current = list_one.rbegin(); while (current != list_one.rend()) cout << *current++ << ; list_one.sort(); list_one.sort(intCompare); //assume intCompare is a functor int num = 0; count(list_one.begin(), list_one.end(), 5, num); // using generic count function on list copy(list_one.begin(), list_one.end(), list_two.begin()); //copy list_one into list_two starting at the first element. //list_one = {1, 2, 3}, list_two = {6,7,8,9} => list_two = {1, 2, 3, 9} list<int>::iterator five = find(list_one.begin(), list_one.end(), 5); Sequences and containers Class bitset deque list queue stack Vector Header <bitset> <deque> <list> <queue> <stack> <vector> STL Sequence Container operations expression X(n, t) X a(n, t); X(i, j) X a(i, j); return type assertion/note pre/post-condition post: size() == n. constructs a sequence with n copies of t. post: size() == distance between i and j. constructs a sequence equal to the range [i,j). Container operations cont. . . a.insert(p,t) iterator a.insert(p,n,t) result is not used a.insert(p,i,j) result is not used a.erase(q) result is not used a.erase(q1,q2 result is ) not used inserts a copy of t before p. inserts n copies of t before p. inserts copies of elements in [i,j) before p. erases the element pointed to by q. eras...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Bowling Green - CSC - 3410
Stacks &amp; Queues Container AdaptersKen Nguyen Spring 2002Introduction Stacks and queues are parts of our life. For example: Stack of papers A stack of disks Elements must be added to and removed from the top of the stack. A queue of people wai
Bowling Green - CSC - 3410
Chapter 5 Design PatternsKen Nguyen Spring 20025. 1 What is a pattern? A design pattern describes a problem that occurs over and over in software engineering and then describes the solution in a sufficiently generic manner as to be applicable in
Bowling Green - CSC - 3410
_ __25 Algorithms library [lib.algorithms] _ __1 2This clause describes components that C+ programs may use to perform algorithmic operations on containers (23) and other sequences. The following subclauses describe components for non-modifyi
Bowling Green - CSC - 3410
RecursionKen Nguyen Fall, 2003Basic Recursion Rooted in mathematics, holds true for positive numbers n A lot of formulas are recursive Correctness is proved by induction Induction Proof: =&gt; Basis: true for very simple case =&gt; Inductive hypot
Bowling Green - CSC - 3410
Chapter 3 TemplatesKen Nguyen Spring 20023.1 What is a Template A mechanism for writing routines that work for arbitrary types w/o knowing these types, i.e. type independent Most likely be seen in generic algorithm implementations, i.e. sorting
Bowling Green - CSC - 3410
Chapter 1 Arrays, Pointers, and StructuresKen Nguyen Spring 20021.1 What are arrays Aggregate: collection of objects stored in one unit Arrays: indexed collections of identicaltype objects. Pointers: objects are used to access other objects.
Bowling Green - CSC - 3410
Sets &amp; MapsKen Nguyen Spring 2002Introduction Set: An un-ordered data collection Allows: adding an element, removing an element, and testing whether an element is in the collection in O(logn). Bitset: Stores a set as a series of bits. Bitse
Bowling Green - CSC - 3410
0 1 2 3 4 5 610 11 12 13 14 15 1620 21 22 23 24 25 2630 31 32 33 34 35 3640 41 42 43 44 45 4650 51 52 53 54 55 56
Bowling Green - CSC - 3410
abcd5 lines 8 words23 char
Bowling Green - CSC - 8840
DEVS and DEVS Model Dr. Xiaolin HuDr. Xiaolin HuOutline Review of last class DEVS introduction How DEVS model works Simple atomic models (SISO) Simple t i Si l atomic models ( ith multiple ports) d l (with lti l t ) Simple coupled modelsD
Bowling Green - CSC - 8840
Homework 2 (Due: Feb 23) CSC8840, spring 2009 Dr. Xiaolin Hu Consider a sheep-grass predator-prey system. Below are the rules 1. The initial populations and positions of sheep and grass are manually set or randomly generated. 2. A sheep eats all adja
Bowling Green - MATH - 1070
WhatisStatistics?DefinitionofStatistics Statisticsisthescienceofcollecting,organizing,analyzing, andinterpretingdatainordertomakeadecision.BranchesofStatistics Thestudyofstatisticshastwomajorbranches descriptive(exploratory)statisticsandinferen
Bowling Green - CSC - 2311
Chapter 10 Summary (partial)arrays, array limits, passing arrays to functions CSC 2311ArrayAn array carries a set of items type of each item (element or base type) must be the same elements can be accessed by index 0, 1, 2, . , size-1 the bas
Bowling Green - CSC - 2310
Java's String ClassSo far in this course, we've seen what a class declaration looks like, and we've seen how to create objects and perform operations on them. Much of the time, however, we won't need to create our own classes, because the Java AP
Bowling Green - CSC - 2311
Chapter 5 SummaryIO streams, character IOStreamsApplies to any time-sequenced data list, to or from, keyboard/console/file/network.File StreamApplies to an external file (hard disk, USB disk, CDROM, floppy, etc.) Requires a file name to acces
Bowling Green - CSC - 8350
DEVSJAVA Set-up Guide Note: the following instructions are based on JBuilder. If you use Eclipse, you should adapt the these instructions according to the Eclipse environment. In any case, the basic idea is to create a new project and add the devsjav
Bowling Green - ACCT - 2102
Principles of Accounting II Chapter 24: Statement of Financial PositionBalance Sheet (Statement of Financial Position) Assets oo Liabilities oo Owners equityBalance Sheet: Whats Not on It Assets not arising from a transaction or event o
Bowling Green - ACCT - 2102
Principles of Accounting II Review of FundamentalsWhat Is Accounting Anyway? _ __ of _Accounting as an _ _ Financial information is needed to make __.Imagine making decisions based solely on _.Accounting provides a process for _ (in jou
Bowling Green - FY - 2001
Proposal for the Use of the FY2001 Technology Fee Submitting Organization(s): Anthropology and Geography Contact Person (Name, email phone): Zhi-Yong Yin, gegzyy@panther.gsu.edu, 1-18261. Executive SummaryThis project will have a university-wide i
Bowling Green - MBA - 8155
Process Analysis and DesignOperations Strategy Process Analysis Manufacturing Services Service Classifications Service System Design Matrix Service Blueprinting Waiting Line Analysis62Queues (Waiting Lines)People waiting to be served/machines
Bowling Green - MBA - 8155
ProjectManagementProjectseriesofrelatedjobsusuallydirectedtoward somemajoroutputandrequiringasignificant periodoftimetoperform. planning,directing,andcontrollingresources (people,equipment,material)tomeetthe technical,cost,andtimeconstraintsoft
Bowling Green - MBA - 8155
WhatisSupplyChainManagement?Supplychainisatermthatdescribeshow organizations(suppliers,manufacturers, distributors,andcustomers)arelinked together. Supplychainmanagementisatotalsystem approachtomanagingtheentireflowof information,materials,andse
Bowling Green - MGS - 8760
Chapter 12Design for Six SigmaMANAGING FOR QUALITY AND PERFORMANCE EXCELLENCE, 7e, 2008 Thomson Higher Education Publishing1DFSS ActivitiesConcept development, determining product functionality based upon customer requirements, techn
Bowling Green - MBA - 8155
WhatisInventory?DefinitionThestockofanyitemor resourceusedinanorganization Rawmaterials Finishedproducts Componentparts Supplies Workinprocess1Irwin/McGrawHillInventorySystemPurposeThesetofpoliciesandcontrolsthat determinewhatinvento
Bowling Green - BIO - 6102
updated 4/21/2009Biol 6102: NeurobiologyAction Potentials Chapter 4Important features of the action potential Threshold o all or none o Action potentials are regenerative Action potential signaling Digital Code o Timing when action potentials
Bowling Green - RSEALS - 1
RomySeals TimeSeriesForecastingReebokshoesales Objective AnalystsatReebokwerepresentedwithquarterlyhistoricalsalesdatafortennis shoesales.Theanalystsweretaskedwithevaluatingthedataandpresenting recommendationsforfutureproductioncapacity.Theissuesthey
Bowling Green - RSEALS - 1
MonteCarlo Simulation What is Monte Carlo Simulation? A problem is complex when you have to take into effect several variables. The human mind is only capable of dealing with one variable at a time it cannot process multiple variables simultaneou
Bowling Green - RSEALS - 1
OptimizationChandlerOil SituationDescriptionandOverallObjective ChandlerOilisseekingtomaximizetheirprofitbysellingamixofgasolineandheating oil.Theseproductsaremadeusingamixoftwotypesofcrudeoil.Theycurrentlyhave alimitedsupplyofthetwotypesofcrudeoilan
Bowling Green - YTHAM - 1
PROJECT 1: TIME SERIES FORECASTINGBy Yew Tham (Chris) MGS 8150 Summer 2007INTRODUCTION Dell Computer Inc. is evaluating customer service improvements which include building a new customer care center in Charleston, South Carolina. The facility req
Bowling Green - RSEALS - 1
RomySeals RegressionAnalysisPricingtheCsofDiamondStones Objective Thedatasetchosenforthisprojectwasdiamondpricesforvarioussizeand qualitystones.Theobjectivewastopredictthedependentvariablepriceofa rounddiamondusingtheindependentvariablesofcaratweight
Bowling Green - SAHUJA - 1
Project 1, MGS 8150, spring 06 by Sanjay Ahuja Objectives Find quarterly sales Projection for 4 quarters Look for trend and seasonality in data set, How much trend and seasonality contribute in explaining variation of dependent variable? I got my raw
Bowling Green - HJIMENEZSA - 1
MONTE CARLO SIMULATIONWhat is Monte-Carlo Simulation?First, we need to define what is simulation? Simulation refers to any analytical method used to imitate a real life system. It is especially useful when other types of analysis are very complex.
Bowling Green - HJIMENEZSA - 1
Optimization ProjectDenisse wants to make some money on her spare time, she enjoys investing money on the internet and selling and buying stuff on e-bay. Because she has been doing both activities for a long time she knows exactly the constraints th
Iowa State - STAT - 402
JMP Output for Egyptian Skull DataOneway Analysis of BL By Year110 105 100 BL 95 90 85 80 -4000 -3300 -1850 Year -200 150 Each Pair Student's t 0.005Oneway Anova: BL Summary of Fit Rsquare Adj Rsquare Root Mean Square Error Mean of Response Obser
Iowa State - STAT - 401
Clock data: un-centered and centered variablesCorrelations: un-centered variables Age Bidders Age*Bidders Age 1.0000 -0.2537 0.3635200 180 160 140 120 17.5 15 12.5 10 7.5 5 2500 2000 1500 1000 Age*Bidders Bidders AgeBidders -0.2537 1.0000 0.7916
Iowa State - STAT - 401
Stat 401 B Lecture 11Multiple RegressionA single numerical response variable, Y. Multiple numerical explanatory variables, X1, X2, Xk1Simple Linear RegressionY = Y | x + Y = 0 + 1 x + 2Multiple RegressionY = Y | x1 , x2 ,., xk + Y =
Iowa State - STAT - 401
Evaluation and Test Score Scatter PlotsPlot of Evaluation score and Test 1700 600 EVALEVALPlot of Evaluation score and Test 2700 600 500 400 300 200 110500 400 300 200 0 50 Test1 100 150120130140 Test2150160170Plot of Evaluation
Iowa State - STAT - 401
JMP Output for Body Mass/Bite Force DataPlot of Bite Force (N) By Body Mass (kg)1500 1250 1000 750 500 250 0 0 25 50 75 100 125 Body Mass (kg)Bivariate Fit of Bite Force (N) By Body Mass (kg)1500 1250 1000 750 500 250 0 0 25 50 75 100 125 Body M
Iowa State - STAT - 401
Stat 401 B Lecture 29Simple Linear RegressionExample - mammals Response variable: gestation (length of pregnancy) days Explanatory: brain weight1Simple Linear RegressionPredicted Gestation = 85.25 + 0.30*Brain Weight R2 = 0.372, so only 37.2%
Iowa State - STAT - 496
STAT 496, Spring 2009Homework Assignment #1, Due by Friday, January 30 1. The luminance of an indicator bar is a critical quality characteristic for an indicator assembly. Luminance is measured in foot-Lamberts (fL) with a minimum specification of 1
Iowa State - STAT - 401
Stat 401BLab 9: Due November 18Fall 2008Below are the Olympic Gold Medal 200 m dash times for women and men from 1948 through 2004. Year 1948 1952 1956 1960 1964 1968 1972 1976 Womens Time 24.40 23.70 23.40 24.00 23.00 22.50 22.40 22.37 Mens Ti
Iowa State - STAT - 401
Using Brain Weight to Predict Gestation in MammalsBivariate Fit of Gestation By Brain Weight500 400 Gestation 300 200 100 00 500 1000 BrainWgt 1500Linear Fit (All 50 mammals) Predicted Gestation = 85.248543 + 0.299867 Brain Weight Summary of Fit
Iowa State - STAT - 401
JMP output for Partial F-tests Teacher Evaluation DataResponse: Evaluation Explanatory: Test 1600 EVAL Residual 0 50 Test1 100 150 550 500 EVAL 450 400 350 300 200 150 100 50 0 -50 -100 -150 300 350 400 450 500 550 600 EVAL PredictedSummary of Fi
Iowa State - STAT - 401
Distributions of Measurements on MammalsBody Weight Brain Weight Quantiles 100.0% 75.0% 50.0% 25.0% 0.0% maximum quartile median quartile minimum 1320.0 128.9 16.3 4.0 0.1440 Count 30 20 10 0 50 100 150 200 250 300Brain Weight Moments Mean Std D
Iowa State - STAT - 451
153 189 221 215 302 223 201 173 121 106 86 87 108133 177 241 228 283 255 238 164 128 108 87 74 95145 200 187 201 292 220 233 172 119 81 65 76 74111 170 243 178 248 202 163 139 120 96 95 53 94
Iowa State - STAT - 528
FeetMinutes04.90257.41506.19755.571005.171256.891507.051757.112006.192258.282504.842758.293008.913258.5435011.7937512.1239511.02
Iowa State - STAT - 528
SalesAccounts36707534741071741765031230589025541101656124200320013052181605195201
Iowa State - STAT - 500
200 differences by bootstrapping, sorted in ascending order-0.467 -0.437 -0.198 -0.1 -0.036 0.062 0.224 0.336 0.644 0.748 0.894 0.902 0.917 0.942 1.251 1.277 1.347 1.353 1.385 1.5 1.516 1.539 1.549 1.581 1.648 1.679 1.798 1.825 1.862 1.936 1.945 1
Iowa State - STAT - 402
strain manure block yieldS23 H 1 299S23 H 2 318S23 H 3 284S23 H 4 279S23 A 1 247S23 A 2 202S23 A 3 171S23 A 4 183NZ H 1 315NZ H 2 247NZ H 3 289NZ H 4 307NZ A 1 257NZ A 2 175NZ A 3 188NZ A 4 174X H 1 403X H 2 439X H 3 355X H 4 324
Iowa State - STAT - 402
trt year block yield1 1 1 2301 1 2 2161 1 3 2191 1 4 2001 2 1 3241 2 2 3171 2 3 3571 2 4 3621 3 1 5121 3 2 4481 3 3 4961 3 4 5402 1 1 2122 1 2 1902 1 3 1512 1 4 1502 2 1 4152 2 2 2962 2 3 2782 2 4 3362 3 1 5842 3 2 4712 3 3 399
Iowa State - ECON - 455
Lapan Midterm Exam #2 Answer Any Three Questions. Answer all parts to each question.Econ 455 Spring 20021. Consider the market for rice within a small country (Agraria). The domestic supply and demand curves for rice are given by:Q d = 200 3P
Iowa State - ECON - 455
Econ 455 Spring 2008 Answers - Problem Set 1 (Producer and consumer surplus). 1. A consumer has the (quasi-linear) utility function: U ( x, y ) = x + 100 y y 2Lapanand Px , Py denote prices the individual pays for goods x and y, respectively. a)
Iowa State - ECON - 455
Fall 2004 Econ 455 Answers to Problem Set 2Harvey Lapan1. Consider the Ricardian model, with two countries, the U.S. and Mexico. The US has 100 worker/hours and Mexico has 300 worker/hours. Labor productivities in each country are given by: Margi
Iowa State - ECON - 455
Spring 2008 Econ 455 Econ 455 Answers - Problem Set 4Harvey Lapan1. (Factor movements) There are two countries, each producing one good (the same good) using land and labor with the following technology: US: Q us = 80 T us( ) (L )12us 1 2;
Iowa State - ECON - 207
ECONOMICS 207 SPRING 2007 EXAM 5Problem 1 (20 Points). For the following problem, write an equation that represents prot as a function of the input x. Write it in the form = pf(x)-wx and then simplify the expression. Then nd the rst and second der
Iowa State - ECON - 207
ECONOMICS 207 FALL 2008 LABORATORY EXERCISE 12 13th N ovember 2008 Problem 1: Dierentiate the following functions with respect to x a:3 ln[(x2 + 3x + 1)2k ]b:x3 ln (5x) + x2 e3x2c: x e3 +2x2 +5 2x2 4x2 +3x+2d:[ln(2x2 + 3x + 2)2 ]3k1e:
Iowa State - ECON - 207
ECONOMICS 207 SPRING 2005 PROBLEM SET 13Problem 1. The cost function for a rm is a rule or mapping that tells the total cost of production of any output level produced by the rm. If y represents the output of the rm, then the cost function is given
Iowa State - ECON - 207
ECONOMICS 207 SPRING 2007 PROBLEM SET 13Problem 1. For the following problem, write an equation that represents prot as a function of the input x. Write it in the form = pf(x)-wx and then simplify the expression. Then nd the rst and second derivat
Iowa State - ECON - 207
ECONOMICS 207 SPRING 2007 PROBLEM SET 12 Consider the following matrices and vectors. P = 2 1 , 5 2 2 , 1 Q = 1 1 3 4 3 6 , 3 2 2 1 4 , 7 p =q =Problem 1. Find the determinant of the matrix P.b. Find the inverse of the matrix P using t
Iowa State - ECON - 101
Economics 101 Spring 2000 Section 4 - Hallam Exam 4A - Blue 1. Marginal revenue measures a. the change in cost required to produce one more unit of output. a. the change in output that can be obtained from one more dollar of expenditure. a. the chang
Iowa State - ECON - 101
Econ 101 Section 4 - Quiz 6 Table 1. Use the Ajinomoto and ADM payoff matrix to answer the questions below Make 30 mil lbs Make 30 mil lbs ADM Make 40 mil lbs 200 160 e. none e. zero e. zero e. zeroe. zeroAjinomoto Make 40 mil lbs 180 150 15020