Remember Me Forgot your Password?

Forum: Electrical & Computer Engineering :: Data Structures & Algorithms :: Linked Lists  New Topic
Probelm #1 Reply
Author Message
nak31 Probelm #1 Mon 20 Apr 2009 8:29:00 PM
Student
Joined Tues 31 Mar 2009
Posts 511

What would this program print after executing:

void main()

 

{AList<int> l1(20);

 

 l1.insert(2);

 l1.append(12);

 l1.insert(15);

 l1.append(88);

 l1.insert(44);

 l1.setPos(2);

 l1.next();

 l1.next();

 l1.print();

}


Student Rating3.9/5
nak31 Mon 20 Apr 2009 8:30:00 PM
Student
Joined Tues 31 Mar 2009
Posts 511

Solution 1:

Inserting is always done after the fence.

Appending is done at the end of the list while leaving the fence unchanged.

Next() moves the fence one step to the left

Setpos() puts the fence in the specified position

 

Inserting 2:         <|2>  

Appending 12:  <|2 12>

Inserting 15:      <|15 2 12>

Appending 88:  <|15 2 12 88>

Inserting 44:      <|44 15 2 12 88>

Setpos(2):         <44 15 | 2 12 88>

First next:          <44 15 2 | 12 88>

Second next:    <44 15 2 12 | 88>

 

 

Output:

<44 15 2 12 | 88>


Student Rating3.9/5
Student Rating2/5
pyari Mon 5 Mar 2012 4:47:00 AM
Student
Joined Mon 5 Mar 2012
Posts 1

Write an algorithm to find the largest number in the list of n numbers. What is the time complexity of this algorithm?


1
© Copyright SolveMyProblem.Net 2017