{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2c03-review - 00046 - ↑ celltype ↑ celltype var p ↑...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
2 if (p .next <> nil) p := p .next ; while (p .next <> nil) do begin p .next := p .next .next; if (p .next <> nil) p := p .next ; end p := L1; while (p .next <> nil) do p := p .next ; p .next := L2 .next; return(L1); end The time complexity is O(m+n). c.[6] MIDDLE(L). The procedure returns the middle element if the list contains odd number of elements, and it returns a list containing two middle elements if the list contains even number of elements. For instance if L= 2,3,1,4,5,6, then MIDDLE(L)=1,4, if L= 2,3,1,4,5,6,10 then MIDDLE(L)=4. function MIDDLE(L:
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ↑ celltype;): ↑ celltype; var p : ↑ celltype; var n,i : integer; begin p := L; n:=0; while (p ↑ .next <> nil) do begin p := p ↑ .next ; n:= n+1; end if ((n mod 2) =1) then begin p := L; for (i:=1 to (n div 2) do p ↑ .next := p ↑ .next ↑ .next; p := p ↑ .next ; for (i:=1 to (n div 2) do p ↑ .next := p ↑ .next ↑ .next; end else begin p := L; for (i:=1 to (n div 2 )-1) do p ↑ .next := p ↑ .next ↑ .next; p := p ↑ .next ↑ .next ; for (i:=1 to (n div 2)-1) do p ↑ .next := p ↑ .next ↑ .next; end return(L); end...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern