int lastof(const int a[], int aLen, const int b[], int blen) { int res = 0; for (int i = 0; i < alen; i++) { for (int j = blen; j >=0 ; j--) if (blj] == a[i]) { if(res
int lastof(const int a[], int aLen, const int b[], int blen) { int res = 0; for (int i = 0; i < alen; i++) { for (int j = blen; j >=0 ; j--) if (blj] == a[i]) { if(res
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
![Write the function lastOf which searches the array a for the last occurance of any value contained
in the array b. Returns the index if found. If not found, return -1.
arrays.cpp
1
#include <cstddef>
2
3
int lastof(const int a[), int alen, const int b[], int blen)
4
{
int res = 0;
for (int i = 0; i < alen; i++) {
for (int j = bLen; j >=0 ; j--)
if (b[j] == a[i])
{
if(res<j)
{res=j;}
}
else
14
res = -1;
}
return res;
15
16
17
18 }
CodeCheck
Reset
Testers
Running Tester.cpp
fail fail pass pass fail
al->[1, 9, 4, 5, 1, 5, 1, 12, 8, 11, 2, 11, 7, 8]
b1->[7, 5, 9]
last0f(al, 14, b1, 3): -1
Expected: 12
al->[1, 9, 4, 5, 1, 5, 1, 12, 8, 11, 2, 11, 7, 8]
b2->[7, 7]
lastof (al, 14, b2, 2): -1
Expected: 12
a2->[3, 2, 1, 14, 10, 6, 13, 1ө, 11, 13, 14]
b2->[7, 7]
lastof (a2, 11, b2, 2): -1
Expected: -1
а2->[3, 2, 1, 14, 10, 6, 13, 1ө, 11, 13, 14]
b1->[7, 5, 9]
last0f (a2, 11, b1, 3): -1
Expected: -1
а2->[3, 2, 1, 14, 10, 6, 13, 10, 11, 13, 14]
b3->[11, 2, 1, 15]
lastof (a2, 11, b3, 4): -1
Expected: 8
Score
2/5](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe2932faa-b49a-4196-8420-f277821525a8%2Fd1bbce93-e0b2-455b-8401-0351bb40adb2%2Forzvli8_processed.png&w=3840&q=75)
Transcribed Image Text:Write the function lastOf which searches the array a for the last occurance of any value contained
in the array b. Returns the index if found. If not found, return -1.
arrays.cpp
1
#include <cstddef>
2
3
int lastof(const int a[), int alen, const int b[], int blen)
4
{
int res = 0;
for (int i = 0; i < alen; i++) {
for (int j = bLen; j >=0 ; j--)
if (b[j] == a[i])
{
if(res<j)
{res=j;}
}
else
14
res = -1;
}
return res;
15
16
17
18 }
CodeCheck
Reset
Testers
Running Tester.cpp
fail fail pass pass fail
al->[1, 9, 4, 5, 1, 5, 1, 12, 8, 11, 2, 11, 7, 8]
b1->[7, 5, 9]
last0f(al, 14, b1, 3): -1
Expected: 12
al->[1, 9, 4, 5, 1, 5, 1, 12, 8, 11, 2, 11, 7, 8]
b2->[7, 7]
lastof (al, 14, b2, 2): -1
Expected: 12
a2->[3, 2, 1, 14, 10, 6, 13, 1ө, 11, 13, 14]
b2->[7, 7]
lastof (a2, 11, b2, 2): -1
Expected: -1
а2->[3, 2, 1, 14, 10, 6, 13, 1ө, 11, 13, 14]
b1->[7, 5, 9]
last0f (a2, 11, b1, 3): -1
Expected: -1
а2->[3, 2, 1, 14, 10, 6, 13, 10, 11, 13, 14]
b3->[11, 2, 1, 15]
lastof (a2, 11, b3, 4): -1
Expected: 8
Score
2/5
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 1 images

Similar questions
Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY