This method extracts an object from the beginning This method inserts an object at the end of the This method inserts an object at the beginnig of Program the Node class, the List class and the following methods of the List class: If currentPosition is pointing to null, nothing is extracted and null is returned. After the insertion, currentPosition must point to the new node inserted.Įxtracting data from the list: return the data pointed by currentPosition, delete the node, and moves currentPosition to the next node ( currentPosition will point to null if there is no next node). When currentPosition is null, the new node is inserted into the top of the list. the new node will follow the node currently referenced by currentPosition. Insert new data in the list: a new node is inserted to save this data, immediately following currentPosition, i.e. If it is required to move backwards more positions than number of nodes from the current position up until the first node of the list, the reference will remain in this first node. If the list is empty or the number of positions to move backwards is not greater than zero, nothing is done. Move the currentPosition reference backwards: the reference currentPosition must go backwards as many positions as indicated. If currentPosition points to null before proceeding, it is first placed pointing to the first node of the list, and then moved forwards the specified number of positions minus one (for example, if it is required to move 5 positions forwards and currentPosition points initially to null, then currentPosition is first placed pointing to the first node, and then moved 4 positions from this first one). If it is required to move it forwards more positions than number of nodes from the current position up until the end of the list, advance currentPosition only until the last node. If the list is empty or the number of positions to move forwards is not greater than zero, nothing is done. The Cars will be a part of a text file called cars.txt (we will get the name as input) and this file will contain the car_id and the boat preference (that doesn’t matter here) like this: cars.Move the reference position forwards: the reference is moving forwards as many positions as indicated. The Node will contain a car_id and a pointer to the next one inside of the Linked List. a Top Node Pointer for the Stack and a Front and Rear Node Pointer for the Queue.the sailing number (to write into files).the capacity (to check if the Boats are full).The Cars will first go into Boat S, move into Boat Q and then finish their Sailing! But, this time the Cars don’t choose in which Ferry Boat they want to go in (the text file remains the same tho!). One Boat will work like a Stack and one like a Queue and both will use a Linked List Structure. In the same way as last time we will have two different kinds of Ferry Boats and Cars that want to get on board of them. I will explain everything the same way I explained it last time! So, without further do. Here the promised second part! Today, we will make a similar Exercise to the last one that you can find here, where we will create Stack and Queue Ferry Boats that carry Cars using Linked Lists! We will not do the exact same Exercise, but It’s tweaked a little bit. C Stack-Queue Exercise using Linked Lists
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |