6.5.8. Replacing an array element-element is give

6.5.8. এৰে উপাদান এটা সলনি কৰাহৈছে

In the previous problem, for replacing an existing element with a new one, we were give the index where we were to place the new element. In this problem, we are not give the index We are given the element that to be replaced.

পূৰ্বৱৰ্তী সমস্যাটোত, এটা বিদ্যমান উপাদানৰ সলনি নতুন উপাদান এটা ৰখাৰ বাবে, আমি নতুন উপাদানটো ক’ত ৰাখিব লাগিছিল তাত সূচী টো দিয়া হৈছিল। এই সমস্যাত, আমাক সূচী দিয়া নহয় আমাক সলনি কৰিব লগা উপাদানটো দিয়া হৈছে।

Hence, our first job is to find the index of the element that is to be replaced. For this, we go through the array element and we make a comparison.

সেয়েহে, আমাৰ প্ৰথম কাম হৈছে সলনি কৰিব লগা উপাদানটোৰ সূচী বিচাৰি উলিওৱা। ইয়াৰ বাবে, আমি এৰে উপাদানৰ মাজেৰে যাওঁ আৰু আমি এটা তুলনা কৰোঁ।

When we get a match, we place the new element in that position using the index. The following code segment shows this Line number 7 makes the comparison here.

যেতিয়া আমি এখন মেচ পাওঁ, আমি সূচী ব্যৱহাৰ কৰি নতুন উপাদানটো সেই স্থিতিত ৰাখোঁ। নিম্নলিখিত কোড খণ্ডটোৱে দেখুৱায় যে এই শাৰী নম্বৰ 7-য়ে ইয়াত তুলনা কৰে।

This will replace all at the occurrences of the given element. For example, if the array looks like above and if we want to replace number 5 with 0, the following will be the status of the array.

ই প্ৰদত্ত উপাদানটোৰ ঘটনাবোৰত সকলোবোৰ সলনি কৰিব। উদাহৰণ স্বৰূপে, যদি এৰেটো ওপৰৰ দৰে দেখাযায় আৰু যদি আমি 5 নম্বৰটো 0ৰ সৈতে সলনি কৰিব বিচাৰো, নিম্নলিখিতবোৰ হ’ব এৰেৰ স্থিতি।