This video demonstrates how to implement fundamental data structures and algorithms in Python, including linear queues with enqueue/dequeue operations, insertion sort for array sorting, binary search for efficient element lookup, and linked lists with node-based data storage and manipulation. The instructor emphasizes understanding core concepts through practical code examples, showing how to manage pointers, handle file I/O with exception handling, and implement object-oriented programming principles for data structure management.
Deep Dive
Voraussetzung
- Keine Daten verfügbar.
Nächste Schritte
- Keine Daten verfügbar.
Deep Dive
9618 May June 2025 P43 | Yearly Past PaperHinzugefügt:
Okay brother, now I am going to quickly solve another paper of yours. That is going to be May June 2025 9618 Paper Four Variant Three. This time variant threes are different from variant one and two.
So we will solve these also because the more practice you have, the better it is. So, let's just quickly go through it. Now I will not go into so much detail in the evidence document. And I'm just gonna be solving it and explaining you all of the questions. Let's say Bismillah.
Let's start with the first ah question. There is a common question before us.
We have a file which is known as q data.xt now it contains all the integer values which are of course stored in string format. It is a text file.
So we have created three files.
Question One Underscore J25py, Question Two, Question Three, Question Four. All the files are ready for you guys. I am just supposed to now you know solve them and quickly read and try to understand for you guys. Ok?
Good sir.
A program reads data from a text file. There is a file. It will read data from it and store it in a queue. The Linear Queue. Now we have to make a linear queue.
That means we're not supposed to worry about the things like circular queues, which is where you have to rotate your pointers to get them back above their initial positions. So, you are not supposed to worry about it.
Because it's a linear queue.
Stard as a one d array of up to 50 arrays the queue has the following patterns. It has some following pointers which are initialized to negative one. The tail pointer is initialized to negative one.
So all these things do not matter to us. It's just whether you want to do the increment earlier or later. It just makes a slight difference to the code. So let's just get done with this.
A is saying Q is a global array. Create a global array of 50 integers with all elements initialized to negative one in the main program. So let's do this quickly.
The first thing that comes is your declaration, so declare a ui colon array in which we have to mention all the elements 0 colon 49 and this is our integer based array, so this has become our integer based array and after that I am suppose to declare the head pointer and your declare head pointer as an integer, I am going to copy this, after this, okay, its speed will be increased a bit and we will try to finish it as soon as possible for you guys because of course you guys don't have much time. ok sir.
This is initialized. Basic declaration etc. has been done. Now let me do them as global as well global QUI QUI and after that global head pointer global tail pointer.
This is all your basic declaration.
After that we also have to assign values.
Right program code to declare and initialize also has to be done. So this is in three marks in which initialization will also have to be done.
So let's just do that. Store Q UE inside UE. What to store? Negative one * 50 times.
fixed bugs? So this work has been done.
After that we create the value of the head pointer.
end pointer = negative one tail pointer = 1 correct g. Now the next point is point B in which he is making you code the inque. There is a basic code in which you just have to check if you have space or not. If it happens in different places, then you just increment your tail pointer so that it starts pointing towards zero instead of one. You will go to the first index position and store the data there.
And if your head pointer is negative one just inside the first inqueue, then we move it towards zero.
And that's it. You're just supposed to return and then you're good to go. Correct? Come on, let's just get done with this. The basic code takes an integer parameter to store in the next position. Returns scroll with the queue and the parameter cannot be stored in the queue. Returning through the parameter stored in the queue updates the point is very appropriate. Children's work. Ok? Let's get let's just get done with this.
Def in q u e u e and it's going to take a parameter. Let's just get it data. Then we will have to take some things global.
Let's take global cube because that exists outside the function.
Global tail pointer and then I am suppose to take global head pointer. So we have taken these three things as global values.
Now what I am suppose to do. Now I have to do comparisons with the basics. If the value of my tail pointer is less than 49. That means if it is a value smaller than the maximum index.
So as long as you have to store all your values. Let's see now that imagination is the key here, now imagine all the things. Whenever you go to create a condition, it is very important to imagine.
Now Why Am I Keeping It Less Than 49?
Why Am I Not Keeping It Let's say greater than 49 and something. So think about that, if we have a value of 48 from let's. Correct? The value of the tail pointer was also 48. Currently you have stored data there. You went and checked, you inqueued one more time. It is already 48. The data is available on it. So now always imagine the last element.
So check what? Ah 48 is less than 49 yes it is then tail point equal tail pointer +1 becomes 49 you have gone to 49 you have stored the data as soon as you have stored the data and that is it you are good to go now now you will go and try to enqueue again now 49 is it 49 less than 49 the answer is no it is not so that is it your entire condition has been validated I quickly did the validation using the last value so just keep this thing in mind that you have to do the validation in the way I showed you so what will be the first thing? We'll get tail pointer equals to tail pointer plus on.
As soon as the increment is done inside it, now I have to go to my queue.
Wherever my tail pointer is pointing, I will go there and store my data.
Correct? Right now we do not have to return true. First let's check one more condition that if the value of my head pointer is currently pointing towards negative one, that means it is not looking anywhere.
What will we do with our head guy? We will point the head pointer towards zero and tell you to be careful. The first element has arrived inside our q. It's just a simple game. When all this work is done, your now you are suppose to return true.
Well, make sure that you guys are returning true after like you know getting out of its if condition.
And then we have this scenario in which our queue gets full. In that we have to return the falls. So that's a basic code for q. So we are done with this six marks easy.
Go and paste it in your evidence document. Then we have Part C in which we have to write the code of dequeue in which the next item in the queue is not empty. So whenever it comes to DQ, all our attention always goes towards the head pointer. Because all this work is done by the head pointer, looking at the values of the head pointer, if the value of the head pointer is negative one, that means this Q is already empty. And then if the head pointer is still pointing to that element.
So we will access that element first.
You are not supposed to return it abroad. Because if it is returned then the rest of the code does not work.
So what do you guys have to do first? You removed the value. Then make the head pointer +1. If the value of the head pointer is greater than the tail pointer, then you reset your tail pointer to negative one, head pointer to negative one again so that we can use our queue again. That's it. Let me quickly write a simple code for you guys. Def d e q u e q u e u e ok. Ok ok ok.
We will have to take it global in this also.
Took the global cue. Global tail pointer taken.
Global head pointer taken. Why Tail Pointer? Because we add people from the tail.
But we will need to reinitialize it. So for that the first condition was made. If the value of the head pointer is negative one. That means your Q is already empty. You are supposed to return what? You are supposed to return negative one.
And if it is not, that means if your Q has some value or the other, then first we do one thing, let's create a variable. Will go inside it. We'll go inside our Q.
Wherever our head pointer is pointing, its value is currently stored temporarily. If you return the item here, that means the code next to it will not work. So you are supposed to make sure that you first do all the work and adjust it with the pointer, then you are supposed to return it. So now we used to get the head pointer +1. The head pointer equals to head pointer + 1 so that it now points to the next element.
And if the value of our head pointer is increased by the tail pointer. That means what your q is completely empty. What you should do is you have to get your revalidation done.
Tail pointer equal to negative one. Head pointer is equal to negative one. This work is done. Once all this work is done, now you are supposed to return the item over here. Make Sure That This Particular Return Item Is Not In Your If Condition. It should not be there in the second if condition. Well, we have also done the code of DQ. Copy and paste it into your evidence document. Now let's move on to Part EI. Which is basically related to your ah my bad. Let us move towards file D which is a file related question of yours in which you are being asked that the text file q date stores the positive integers each integer is on a new line in the file the procedure create you have to create a procedure by the name of q which is going to do what it is going to do is to open the file means by opening the file with basic equals we have to open it in read mode we have to read each line one by one for line in file and will read it and use enqueue and we will keep passing it to enqueue we will create a flag type from it and if its value is negative one then we will say q is not full if we create our flag type we will compare it with true and false.
If we are having falls then I am suppose to say useful.
If it is coming true then I am suppose to say successful or whatever it is saying use exception handling when opening and reading from the text file the procedure needs to work profile that contains an unknown number of lines. So, it means we have to do line and file work. It is a very simple job. Let's just get done with this as well.
Def Create.
Hey, what happened my brother?
Create Q and in this the first thing that comes to our mind is exception handling in which we will have to open the file.
File equal to open then the file name comes q ue ue data dotxt comma in read mode. Now after opening the file I have to go to each line one by one. for line in file.
What do we have to do after this? The first thing I need to do is access the number.
Now how will I access that number? Let's just make a variable fett convert it to integer because it's an integer based array line dot strip keep doing it. The dot strip removes the newline character from your file.
In the file which has new line characters on every line, dot script is used to remove it.
After that let's just make a variable called flag and pass this number here by returning flag equals enqueue. So now we have to give a certain output according to whatever value is returned. If return flag equals to equals falls in that scenario what I am suppose to say your q is full print you full right that it in f small we have done it I think that it exit the for loop file dot close and after closing the file what you are suppose to do is accept exception IO error inside which now what we have to do is print the file does not exist so it is easy.
Your code is ready.
Copy and paste the create q. The main program needs extending to call create q. The main program then adds together all the integers contained in q using dq to access each integer. The total is then output. Write program code to extend the main program. Okay, now in the main program you have to use create q in which what will you have to do? A the main program then adds together all the integers stared in the q using dq So what do you guys have to do? The first thing you do is extend the main program needs to call create q. Okay, first you need to call create q.
Okay, okay, okay, I sat down a little bit, I was reading it wrong. You have to call create q. I made the call. Then saying the main program then adds together all the integers stored in the q. You have to add a to all the integers stored in q and total them.
Ok? Using dq to access each integer and dq is used to access.
Well now we have to think of the off course loop stopping condition. So, if my value of a dq becomes negative one, then I am supposed to stop the loop.
That's the condition. Right? So as long as my return, whatever its value is, is the dq value, it is not becoming negative one. I am supposed to keep on continuing with the loop. Let's just try. I'm gonna be doing a flag looping for that. Flag equals two fouls. Then I'm going to add a variable to the total. Total equals to zero while flag equals to false.
Till My Flag Falls. What I am supposed to do? I'm supposed to dequeue a value. Right? I need to deq a value.
How will I get it out now? I'll extract the return value from let = dq whatever the value returned is.
Now I will check this first. If return value is equals to is oh my bad. If the return value is equal to is equal to negative one then I am supposed to do what? If that's equal to negative one.
That means our DQ is all over. I'm just suppose to make my flag ojit. So we will set the flag equals to true. And what will we do inside Elsa?
We have to do the total. Right? So total equals total plus return value whatever is coming is easy for us, friend, it is like a children's game, that's it, it is such a small work. Now we have to print this total.
Then the total is an output right print the total is comma total hopefully it works let's just run the code this whole code your ready. Let's run the code. 3059 Perfect. Everything is perfect. Correct? This is your complete question one. We are done with this. Ok?
Let's move on to the next question.
Question number two now.
Now question number two is related to insertion sort and binary searching. These are the concepts of two things about which your question is two. Let's just get started. In this, of course, I am not going to explain every concept and every logic because of course, its proper detailed classes have been conducted with you guys on how it happens and how it works, so what I want to teach is how to write questions, how to read them, how to answer them, the fear has to be eliminated, this is our main focus, a program sorts the data in the one-dimensional array and of course, I am going to explain as much as I can, whatever I can, I am going to write some comments for you guys so that you guys start understanding, so keep focused with me. A program sorts data into a one-dimensional array.
Data array Ah sorts the data in the one d array. The data is an array named array. And searches that particular array which is date array for specific values. If there are any specific values, they will have to be searched. It stores 40 integer values and is declared local to the main program. Meaning we have it in the program. Ok?
Write program code to create data array.
You have to create a date array and initialize it with these certain values which we have given below.
So the first thing what I'm gonna be doing is first I'm gonna be writing my comments declare data array colon array how many? 14 So zero colon up to 13 off integer. This is the basic declaration of your array. And after that what you are supposed to do is you are supposed to store these values.
Data array is equal to 0 3 4 56 67 44 432 31 3 4 5 45 6 54 one. Well, whenever such questions arise, make sure to validate this.
You have not put the comma wrong or written the number wrongly.
So let's just validate 154 six and after that 45 3 45 31 32 43 and {comma} 44 {comma} 67 {comma} 56 {comma} ah 56 is correct. {comma} 4 {comma} 3 {comma} zero. perfect. It turned out great. I think everything is perfect. If there is an issue, we will figure it out in the afterwords. Ok? Let's go. Now let's move ahead quickly. Let's move on to Part B with these things. The function insertionsort takes an array of integers as a parameter. Insertion sort is taking an array from you as a parameter. The function sorts the data into ascending numerical order using an insertion sort. The function returns the sorted array. Insertion sort has just one simple principle. And what is that? The first element is already sorted. He will act as your reference. According to that we have to pick up our second value and find its correct position which we know as the hole position. And we look for him. So what do we do? Are. Let's start the hole position.
Searching starts from the next value and keeps going back, keep going, keep going and keep searching for the values and shifting. Simple as that. Correct?
So let's just quickly write the code for this. Let me explain the whole thing to you.
How you are supposed to do this is an idea sort of thing.
Ok?
We take the data array here. Well, take an array of integers and the function returns the sorted array. Well, it's returning the sorted array itself.
Correct? So perfect. It doesn't matter what we name the array.
Right now I just keep it data array. And after that the first thing that you need is array size. Off course so that we have to control the loop from that. So where do you get the array size from? Length of your data array. And after that what you suppose to do is we run a loop of for.
Whatever values there are, you always have to start it with a pointer and the range will start from one. Why will it start with one? Because zero is the first element.
You have to start with the second element.
And how long should it run? us to array size.
We will store all the values at the correct positions of all the elements one by one.
Correct? Now what you need is always we create a temporary variable.
Creates variables. Now what is that temporary variable? That is the value because off course we will start shifting to the right or left side.
Right? We will pick up our values one by one and shift them to the right side.
So of course that place will be occupied. That space will be used.
It will get replaced. So that value gets lost.
So we create a variable which we call it value to insert. Value to insert. That's going to be my temporary variable where I will be storing my value. From here, right now go to the data array, whatever the value of the pointer is, go there and pick up your data and your hole position, it is basically a position that you are looking for, right? This is the correct position that we are trying to find. What is its name? Its name is hole position. We call it the hole position.
Ah, it starts with a pointer. What do we do now? Let's run a basic for while loop. As long as the value of our hole position is greater than zero. There are two conditions for insertion sort. Or your element is the absolute smallest number. So he comes to the extreme left.
In that the value of hole position becomes zero.
You should restrict your code accordingly.
Either we find a place somewhere in between. How do I get it?
Go to the data array. Let me zoom out a little bit. Let's look at all positions.
My bat. Let's go to our data array. Let's do hole position -1. Let's look at the element behind it. If that value is greater than the value to insert, then we will shift that particular value to the right side. That's it. This is the entire game.
If you are in the loop, if you are inside the loop.
That means one thing that now we have to shift to the right side. The correct position of that element, which is bigger or smaller, is of course somewhere on the left side.
According to my reference array. Now what will we do after this? If you are in the loop then you are suppose to then you should keep finding the hole position. Now you have to keep finding the hole position.
Shifting is also happening inside it while we are also doing this work of shifting to the right. These are the two tasks that are happening inside the loop.
Now which ones are they?
What's the first thing you do? You go to your data array and go to its hole position, that is, the current position, pick up the previous value and bring it forward.
Simple as that. That's it. There is so much work. And keep making your hole position -1.
Hole Position Is Against Hole Position -1. That 's right sir. You changed the hole position to -1. It is coming backwards. It is coming backwards. Now as soon as you guys come out of your vile loop. That means what?
Whenever you are outside the loop, sorry, I have to explain a little bit so that you can understand. That means you have found the right place.
Ok? So for that what you suppose to do is go to the data array. Have to go to the hole position.
You have to go there and insert your value.
Okay sir, your entire insertion sort is ready. OK let's move on to part C now. The procedure output array takes an array of integers as a parameter.
You have to take an array of integers as parameter. After that you guys have The Procedure Outputs Each Element. Well my bad. I am supposed to return the array as well.
Right? I forgot about it. Return data array by exiting the for loop so that we get a sorted array. Now it is saying to create an output array. Takes array of integers as a parameter The procedure outputs each element in the array Takes each element in the array from the first element to the last element. The output is on one line with the space between each number. Okay, but this is related to string concatenation. We will pick up the values one by one and concatenate them. So that's the whole code which you guys are supposed to write. This question has come up many times. So I think if you guys have practiced the past papers then this is something which is not difficult.
Will take a data array. Let's create a string called Make a String Temp. They keep it empty. And what will we do in this? For x and range as many elements as we have.
So for that I'm gonna be using the length of the data array. And we will pick up the values one by one. The strings will go into the tem. We will store the old value of string tem inside it and we will have to convert it into concatenated with your string.
We will have to go to our data array and pick up the value x and along with it we will also concatenate an ad space.
So these are three things which will get interconnected.
When the for loop is ready. I am just supposed to return this value now print string temp that's it easy code is children wala right ji now next thing next thing next thing point d oy let's say we have the first value i zero zero concatenate with space then one then zero becomes one so this is the way we have to create the output let's keep it simple let's move to part d i the main program needs to be extended to output the contents of the unsorted array using output array first you have to create the unsorted array. Then you have to call insertion sort. Then after that you have to call the output array again so that we can see both the things. Ok? Easy code is a child's play.
We will show you both these tasks by doing them. The first thing is going to be inside I DI we have to output normally. Correct? So let's just call it output array. I pass the data array into it. This will give us value. Now let me change my data array. We will call insertion sort and pass the data array to it.
This will sort the array and my data will come inside the array. Now now I am suppose to output it again.
We keep it simple and let's just verify these values first. Let us look at these first. It is sorting it correctly. 0 35 OK 0 1 3 4 6 31 32 43 44 45 54 56 37 45 Perfect.
Everything is perfect. So our entire code is ready till here. Now let's come to Test Your Program. Take a screenshot. This is a child's job.
You guys have to upload the screenshot of the way we ran it. Now let's move on to Part E which is basically related to binary searching. Now what is the point in binary searching? The function search performs a binary search to find the item to find. You guys have to take one variable.
Ah parameter and the name of the item to find is to search within the data array. The function takes two parameters. A data array and integer ah array of integers. Item to find an integer to find an date array. The thing you want to find. The function returns the index of the item defined if it is in the date array and negative one if the item defined is not in the date array. It is a children's job.
Binary search is a very easy code. Everyone should come. There are easy marks. Six marks, these are easy marks. In which you people just have to do some basic things. You people have to understand this thing in a basic way. You take the upper bound, you take the lower bound, you find its midpoint and you see now you have three cases. If the value you are looking for is mid pay.
That means you have found your value. And if it's not mid-pay, it's going to be a great value.
So we're going to raise our lower bound to be +1 from mid.
And if that value is small then what will we do? We'll raise our upper bound to mid-one so we can keep dividing our array into halves.
And if the value of our lower bound exceeds the upper bound. That means that that particular value is not present in your array. It's just a simple game. Let's do that now.
In which we have to take two things.
First we took the data array and what did we take along with it? Items we are looking to find.
Item to point and after that dev search that array comma item to find. Now what do we have to do after this? What should we do? mmmmmmmmmmmmmmmmmm okay Jon was out brother. We zone out first so we find the upper bound. Right?
We can take it out from the length of array, brother. Length of data array - one. Then we find the lower bound. It is always zero. And after that we create some flags of our own, one of which is the value found flag which we initialize to false.
Look, there are many ways to do this but I am doing it in my own way so that you people remain a little familiar with the pattern of my knot in less so that you people understand this thing that yes brother there is nothing which is which is not you know not covered or which is new. So don't worry.
While value found equal to equal to false and not in list equal to equal to false.
What do you guys have to do? First thing first, calculate the midpoint. How is the midpoint calculated? You can use div thing and you can use integer thing to take the lower lower bound plus the upper bound divided by two and take the integer part of it. That's similar to saying your div thing is lower bound plus upper bound div to so diff to is basically saying that you need the integer part after the div if the date array mid point is ok first case let's check if it is equal to what you were trying to find.
That means you have got value.
You are just supposed to see that the value found is equal to true, it does n't matter but still do it so that what you had to do is you are supposed to return the index, so returning the index means you will have to return the mid point, you will have to return the mid point and if this is not the case, it is not at the mid point, then two things will happen, either it will be smaller or it will be a bigger number, then first we will do the bigger case, if that array mid point is greater than the item defined. Meaning what you are trying to find is a small value.
Correct? Look, there is nothing to remember in this.
Just imagine it. If what you are looking for is a small thing. That means it cannot be beyond mid.
So we're going to raise the upper bound to make our mid equal to -1. Simple is that. Mid point -1 and the second scenario inside else that is going to be lower bound is equal to mid point + 1 and after that exit the if condition.
We have to check this in everything. If my lower bound is greater than my upper bound in that scenario I am suppose to say not in less than we will also offset. And you are supposed to return negative one. That's it. This is the complete binary search code for you guys. Correct? It was easy. Let's talk about part if I now.
What things do we have inside it?
The main program needs extending to call search with the sorted array four times. I have to call four times. The first time to find the index of the integer zero. Meaning now we have to find the first zero one by one. Then look for 345 after that. Then find 67, then find two. Have to do it four times. If the integer is found in the array, output an appropriate message that includes the index. If the integer is not found, output that it was not found. There is nothing simple and nothing that is difficult for you. It is a basic job. Quickly you guys will have to find everything one by one. Let me do that for you.
Location is equal to search.
And inside the search we will keep our data array and inside the item to find we will have to keep zero.
This is the first one I am making.
Correct? If you want to make only one then you can copy and paste it. If location is equal to equal to negative one. If negative one is equal to then what I am supposed to say is print am location data not found like to date not found by doing something like this I don't know zero date not found 345 date not found and if negative one is not equal to then what I am supposed to say is data found at index let's just print data found at index comma will put the value of location here. That's it. This is the code. Now let us quickly copy and paste this. How many times do I have to do it? Have to do it four times. It became two, it became three, it became four. Ok? Now just keep changing the locations. Earlier it was zero. Now 345.
And 345 after 67, 67 after two. So, let's run the code. Hopefully, there is no error. If any error occurs, we will just sort it. Okay, negative one that is not found. Easy negative one that is not found. That means what your location was. It is fine even if you do not enter the location. No issue.
Ok? perfect. No worries. That's it. We are done with this code. Now the entire question has become ours. Now let's move on to question number three which is related to linked list.
Moving on to question number three.
Well, question three is this, nowadays a lot of people are asking questions in this manner. So now I have also solved the binary questions which are 41 42.
So let's do it quickly. Don't get nervous in such questions that you don't know what the question is. It's just that you have to keep your concepts strong. So inside the gender list, inside the binary tree, inside the array, it's not about memorization of codes. If you start memorizing the codes, then you will not be able to solve such questions. You will waste your entire 30, 25 to 30 marks. So explain it to them very calmly. Keep imagining.
Today I will show you how to do it properly.
We will try to do this by drawing a little bit on paper and showing you how things are and how you are supposed to do it.
Correct? Good. What are you saying? A program stores data in a long list that is executed using object-oriented programming. The class Node stores data about the nodes. In which we have some nuts present. There is a node in which we have what thing? The data which stores the integer values. Correct? Then there is the next node which stores the next node in a linked list. So a node consists of two things.
One is the data and the other is the pointer and the next node. Now it is not a game of pointers here. The game here is that you have inserted the entire node. Now what does the constructor say? So this makes things easier, a little bit harder.
Because you guys are not aware of the whole situation, aware of the codes. So of course let's see it quickly. Let's try to understand. Let me explain it to you completely. Correct? Now let's create a constructor in which you initialize the data to its parameter value. One will take the data and then initializes the next node. The node that is equal to it will make it nun.
Null means nun in the scenario.
What do you guys have to do after that? Gate data. Have to make a getter. Get Next Node Returns the value of the next node.
That's a very simple not complicated point. Then setNextNode which will take an object of the node and store it inside the next node. It's an easy scene.
Write program code to declare the class Node and its constructor. Use your programming language's appropriate constructor. And that's it. Let's just get done with this as well. In which the first thing we should know is to create a node. Let's do that class node and after that I'm suppose to declare some private attributes private the data. Well sir, how did you know that you had to make this private? Brother, it is a simple scene. All codes are private until and unless it is a recorded it.
Just keep it in mind. And please read the question brother. Everything is in the question. If it is not mentioned then make sure to do it privately. The node will come inside the next node. And after that I am suppose to make a constructor.
Look, and one more thing, do not leave such questions that you say, friend, I don't know at all. Brother, sit and secure your basic easy marks which are of the constructor.
Partial marking also takes place in this. So you are not supposed to worry about it.
We have to take data inside the self.
Just store the value of the data P parameter inside the P colon and cell dot under the data and then store the value of the non non i.e. null inside the next note. Is it okay? Then let's move on to the next part. This is Part A.
What's on the horizon for part two, brother? Write program code for the two get methods. Now two getters have to be created in which get data get next note has to be created. These are easy marks.
Get a data in which we have cell pass.
And then we return the value containing cell dot underscore underscore the data.
Then the def gate picks up the value of the next node. Let's do self and return self dot unders next node value. And after that, you have created these two setters and two getters. Let's move on to part three. Now he is the setter. The Set Next Node is a method you have to set the value of the next node.
It it is taking an object of type node as parameter. And then there is a method on that particular one that will store the parameter inside the next node.
Simple so let's do that def set next node will pass self.
A next node P which is the next node, the node after it will be assigned a parameter in a way. How to do it? We have to set up.
So store the value of next note p inside self dot underscore underscore next note simple this your setter is also ready. Now after this we are coming to the difficult questions.
Let's start with Part B now. Saying The Linked List Stores The class Linked List stores linked lists. Ok? What do we have inside the linked list? You have your head nod. The class that our linked list belongs to has a head node.
It stores the first node in the linked list. Whatever your first node is, that basically represents the start pointer, which is the start pointer.
We are not playing with pointers here.
Here we are storing the values directly. So here we are talking about the head node i.e. the start pointer. The constructor you create is what initializes the head node to a null value. Right now, initially of course, our link list will be empty, so it will point to nun.
After that we have to insert node.
An add method is to create a node in which it creates a new node using its integer parameter, sets this node as a new head node, and updates the next node.
Let's not think about it right now, let's do the basic work which is Part I. Then there's the Remove node.
Finds the first node that contains its integer parameter and removes this node from the linked list. Good remove code to write. Write the code for insertion. Easy.
Then traverse is saying concatenate and returns the integer data in each node in the linked list. Okay, now I have understood a little bit.
I have understood a little bit now, I will see it later. First of all, let's start with this part in which we are only asking you to create a linked list and its constructor. And that's it.
So let's do that a deaf linked list inside which we have to create my bad class.
We Dhan Dhan Dhan Dhan Dhan Dhan Private Head Node Calling Node is correct, you have to create it from no data type, let's start with your constructor define under underscore cell, pass it, take head note p, cell dot underscore underscore head node is equals to head note p, you guys have made the basic constructor ready, now let's start with your insert node, let's move towards part two, what is it saying, now it is important to understand this, this is the whole game, your game is starting from here. The main actual scene, the entire scene, will start here. Let me let me teach you. Saying the method insert node. You guys have to create a method called insert node.
Which is going to take integer as a parameter. Will take an integer value as a parameter. will create a new node. Creates a new No with the integer date as the parameter.
Now they are saying use the new Nads method. Now from here the English starts to become a little strange. So whenever English starts to feel weird, start imagining things and start drawing on your computer. So of course I do have a graphic tablet. But I'm gonna be doing it with a mouse so I can replicate the same situation that you guys are going to be in. Correct? Ok. Now he's saying it is taking an integer as a parameter. It creates a new node with the parameter as the integer date. Slow down translate. It is saying that a new node has to be created by using the parameter value which you will get in parameters. fixed bugs?
perfect. I understood till here. He is saying use the new Nads method. New Nodes method means we have to use the method of the new node that we have created.
Set next node to store the current head node as the next node. You can understand from here. You know it, it starts getting complicated. Let's read it again.
Saying use the new No method setNextNode to store the current head node as the next node.
What are you saying? Let's imagine. It's saying a new node has been created and this is its next node thing. Let's write n.
This is the data. I will write this as d. He is saying that from lets I brought a value of five. That's the five values. Right now there was a nun here. Let's write N for now. Correct? She is a nun. This new node has become yours. When the new node is created. Now he is saying use the new Nads method. Apply the method on it.
SetNextNode. This means that you have to store the next node at the place where the tap is located. To store the current head node. Meaning, this is our link list made from let's.
It is pointing towards the next node.
And then it is pointing towards the next node. In this way it is saying that you should store your new node inside which is currently the head node, that is this one, we have to store its value initially.
So this thing is asking to make a connection like this. Then saying replace head node with the current node. So replace the head node of your link relay with the current node. That means your start pointer will become five. Ok?
I understood the whole game. What it's trying to do is insert whatever you are from the starting position of the linked list.
What did we usually do?
Whenever we used to insert, we used to find the last value inside the linked list, that is, while incrementing the current pointer, the current pointer equals to the linked list current pointer dot next note, we used to go till the end. Used to look for negative one. We used to go there and insert the values. Here he made it even simpler. He is saying store it in the beginning itself. I don't even want to go to the end. Keep storing in the beginning itself. So that's comparatively very easy. So this has become a very childish thing. So now let's quickly write the code for this.
First things first, let me write some proper steps for you guys. Insert node that will take self and data from you guys. Correct? I'm gonna be calling it Node Data. They say no data. Now what is your first step? Step number one in which what do you guys have to do? You are supposed to create a new node. Let's do that.
Create a new no. Correct? How is it made now? New No Is Equ Node which we have created above data type, class, let's pass the data inside it. So we will pass the node data to P. This will create a node for me. As soon as I have the node created. Let's talk about step two. Now in step two we're telling you to use the new nodes method to store the current head node as the next node. The first node will be replaced by the current node, which is currently the first node, in the position held by the new node pointer.
Correct? How will it come? The set of the new node that you have created will go to the next node and in it you will pass the current head node. It became simple.
What connection have we just made? Further, the new node that we have just created in this previous one has also started pointing towards the head pointer, that is, towards where the start pointer was.
Now I'm just suppose to make sure your start pointer points towards the first node. Now we have to change our head node.
Easy friend, it's children's work.
What do you guys have to do now? You have to change your start pointer.
How will you change it? You'll say self dot head node, which is your self dot head node, which is representing the start pointer.
Is equals to new node. That's it. The entire code is done. This is such a childish job. Now let's move on to part three.
Saying The Method Traverse. We have to create a method named after Travers. which concatenates the integer data from the nodes in the linked list starting with the node started in the head node. Meaning we have to start from the head node.
Meaning current pointer equals to start pointer. Then while current pointer ah go to end.
While the current pointer is not equal to negative one. Current pointer equals to next current pointer equals to linked list dot a current pointer equals to linked list current pointer dot next node means we increment one by one what is the game here inside our pointers we have all the nodes present.
So we'll be lifting the whole thing and doing the same thing. So for that we're saying more The method returns the final string each integer ah separated with the space. So the same thing you have to do is form a string also. So let's just call it return string is equals to empty quotation marks. At the moment I have to create my current pointer. I call it the current node. The current node is equal to the one we started with.
So self dot head node. Right?
Oh my bad. Who will make it that way?
Who will create the uncle function? Control X Def Traverse pass self. And after that return string equals empty quotation marks.
Then current node equals to self dot head node means start from starting and keep doing this. While current node is not equal to none. There was negative one there.
Here we have the scenario of the nun.
What else will you do? We will first connect.
Store it inside the return string.
Returns the old value of the string concatenated with the string we need the data for. Right? Where did you get the data from? So we have his getter in place.
Right? So let's first pick up the data.
Go to the current note in the data is equal string dot get data. The data will come to me. Ok?
Return string plus data plus empty quotation marks with space easy done brother.
Your entire code is ready. What are we doing? Picking up data. What are you doing after that? A continues to concatenate.
Now there is the concept of increment.
Scene with increment current pointer. I will do it here. How to do it?
Store it inside your current note.
Go to the current note. The value of its next note.
Where do I get that from?
I will play the gate next note. It is a child's game. It's All About Imagining Things. When all this work is done, now I'm supposed to return your return string thing [nasal sound] thing.
Our entire Travers code is also ready. Now let's come to Part Four. The Last Part for This Whole Paper. That is going to be.
The method removeNode takes an integer parameter to search for and remove from the linked list. The method first checks if the linked list is empty. Will first check if it is empty. If the linked list is empty the method returns false. If it is empty then it will return false. If the linked list is not empty the integer data in the head node is compared to the parameter if it matches the parameter the head node is changed to store the next node. The head node is changed to the next node. Meaning, if it is present in the beginning then we will change our head node and remove the previous element.
If the parameter does not match, the nodes are removed; until either the nodes with a matching integer date are found, the node is removed; the appropriate node is updated and true is returned; and if none of the code contains a matching integer date to the parameter, no nodes are removed and false is returned. So basically we have to write the code for remove node. Our remove node code is a big child job.
What do we do in it? We start from our current node and find its location. Let's play a while loop. And if we find that data to remove is not equal to date to remove, we keep searching and traversing. One note then the second note then the third note current pointer equals to current pointer dot next note. We keep searching by noting the current pointer equals to linkless current pointer dot next and picking up the values one by one by doing dot pointer.
As soon as we get that value, then we apply our own conditions. If we have the value of the current note becomes negative one.
That means he does not exist. Then we have two cases.
And what are those two cases?
Now we just have to connect the pointers. Now there are two cases.
Either it will be the first node or it will be from the middle. If it is the first node then you are just suppose to remove it. Ah you're just suppose to change your head node. Simple is that.
And if there's no first node, then whatever node there is, like our middle node, there will be a front node and a back node. Let me remove this middle one from the let's. If I need to remove the middle one, I need to store the next thing inside its next node. So where will I get that? You will get it from the next node here.
So you will store the current inside the previous.
This is my current one. This is my CP. This is my previous pointer thing. Correct? So I want to store inside previous is current dot next node. So the connection beyond that will be built.
Simple is that. So this is the whole game. It's all about imagination. If you are able to imagine things, it is easy to write the code. You will pass the remove note yourself and you will say data to remove whatever data you want to remove.
Now the first thing we have to do in this is to create our current pointer and previous pointer. Let's just call it the current node.
Current node equals to always start from starting.
Like you guys used to do, current point is equal to start pointer. So that's the same thing. Let's make previous pointer as well. Let's make it in the name of Previous No. Right now I'm just gonna be keeping it non meaning initializing I am.
Step One: I am writing the steps to tell you people.
It is not necessary for you to write. Am find the give me a minute.
Ok. Find the node that you want to delete. How do they find it now? Let's play a loop of while. While current node is not equal to none. Meaning the aim did not reach the end of position.
Is not equal to none and we will have to pick up the data of what is your current node right now.
Dot get data if that is not equal to data to remove simple.
Either it is not equal to data to remove or it has not reached the end. So what will we do now? We will store the current node inside the previous node and increment the current node.
Current node dot get next node.
Simple game. Now as soon as you come out of the while loop, we will have got its correct positions.
Now there are three cases. If the current node is equal to zero, then we are talking about negative one. That means that your value that you want to remove is not in the linked list. So you're just supposed to return false.
And if it is not, not equal to nun, then we have two cases. What are the two cases? Either first or in between, let's do the first one first.
Correct?
If current node is equal to equal to self dot underscore underscore head node. So that means he is present in the starting. Then we have to change our head node. Self dot head node ah inside this we have to store the thing next to it. Right? So we can from self dot head node dot get next node stored the thing next to it and inside else we now have to consider the thing between.
So how do you do the in-between one? Previous node dot Now we have to change the next node of the previous node. So set next node what do we put inside this? will go to your current node.
Its get next node value is easy, my easy kids work. If we are done with these steps then I am supposed to return true. This is it, the entire remove node is ready, your everything is done. Hopefully there is no error in this. I'm gonna be figuring it out. Let's watch it with peace.
Okay, now in the next one, I'm telling you inside A part CI. The main program creates a new linked list object and uses the appropriate method to insert five values with the following integer data values in the order given. The main program then calls traverse, removes the node containing the integer 30 using removeNode and calls traverse again, easy. Let's see if any error comes, we will fix it. Let's create it in the name of created list. In which we will have to create our linked list.
Inside this we have to give our head note. The head note is going to be my two insert first five notes. Correct.
In this we will have to give a head note. While we are creating the linked list, we have to give our ah linked list and give us the head node.
Right? Let me just quickly look into that from back then.
Make it linkless. Store the first node initializes the head node to a null value. Oh ok. So you don't have to initialize this with parameters, my bad. So we will have to change it a little bit.
Initializes head note to a null value. That means there is no parameter involved.
Ok? So the nun will come here. Easy no worries.
Ambulatory. So the nun will come here. So what will happen with this? Meaning initially the gender list is empty.
Ok? perfect. So no parameters in this. Then we have to note created list dot insert.
Which values? The first value is 10. This is going to become my head nod.
Created list dot let me just copy paste. Then we will keep changing the values.
How many are there? Let me just see how many values there are. 1 2 3 4 5 2 3 4 5 After 10 After 20 After 30 After 40 After 50 Hopefully everything works then I'm suppose to call traverse created list dot traverse.
What do we have to do after that?
Okay created list dot traverse now this created list traverse is called and what traverse returns is traverse returns an empty string right so what I am going to do is put this in print so that whatever string comes will be printed at the same time after that I am suppose to remove a node create list dot remove move node inside which we have to put the data to remove. So I am supposed to remove 30 and I am supposed to return your trace again.
OK I think it makes sense. I feel like it makes sense. But let's see if everything works and everything works no break. Okay, perfect. So our first one came to 10. Then 20 became his head note.
Then 30 became the head note. Then 40 became the head note.
Then 50 came in the starting.
Then we removed 30. So 50 40 20 10 perfect everything is fine so that's it we are done with the whole code Alhamdulillah the whole paper is done.
Ah that's it. You will get its version in the description. You guys can look into that and practice as much as you can. Ok take care. Allah Hafiz.
Ähnliche Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











