Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please help class Student (object) ##--init-O functions as the class constructor

ID: 3726256 • Letter: P

Question

please help

class Student (object) ##--init-O functions as the class constructor" def init. (self, none-None, prev None, nxtaNone): self nane none self.prev-prev self.next - nt Using the above class, describe how you would create a queue, a stack and a circular doubly linked list. The class Irepresents a node in a linked list. That means you have to use a linked list as the form of your structure. You can use a narrative description, diagrams or pseudo code to describe how you would use the linked list node(s) in these datoa structures. In essence how would you use a linked list structure to perform the functions of a queue, a stack and a circular doubly linked list. Provide all details from each data structure. Describe how each object from the class would be used. Feel free to add, remove and change the objects in the class to create the proper objects. Uplood a word file for grading. all diagrams and graphics created should be copied and pasted into the word document. I will only accept a single word file or a single PDF file. ouet Starcks & Linked Lists

Explanation / Answer

As per your requirement the below one is solution please follow it

class Student(object):

##"__init__() functions as the class constructor"

def __init__(self, name=None, prev=None, nxt=None):

self.name = name

self.prev = prev

self.next = nxt

Above class has the 3 variables

We can add few more class variables in the above class to maintain the student object easily and identifiable,

The class can be re-written as the below,

class Student (object):

##"__init__() functions as the class constructor"

def __init__(self, name=None, prev=None, nxt=None, major=None, rollNo=None):

   self.student_name = name

   self.student_rollno=rollno

   self.student_major=major

   self.prev=prev

   self.next=next

The class structure is allowing the program to maintain the linked list data structure, since it is having pointer to previous and next objects.

Queue

Queue structure always follows FIFO(First In First Out), to achieve this we have to add the element at the end of the queue and remove it from the first.

Please find the below pseudocode for queue using the above class,

ENQUEUE(object): // To add a queue at the end of queue

if Q.head == NIL: // If already queue is empty add the received object at the beginning of the queue

    object.prev = object.next = NIL // If it is the first element then no previous and no next element

    Q.head = object // now the first element of the queue [Head] is the newly added object

else

    cur = Q.head // already queue is not empty

    while cur.next != NIL // loop till the last element

        cur = cur.next

    cur.next = object // add the object at last

    object.prev = cur // make the previous of the received object to queue’s last element

    object.next = NIL // Since object is last make the next empty or null

DEQUEUE():

// handle empty queue

if Q.head == NIL: // if the queue is empty or 0 elements in the queue

    ERROR! // or something

else

    object = Q.head // make the queue head to next object

    Q.head = object.next // remove the first element in the queue

    if object.next != NIL // check the queue is empty or not

        object.next.prev = NIL // otherwise it points to itself

    return object // the queue after an enqueue

STACK using linked list

ISEMPTY: // check if stack is empty or not

if S.head == NIL // make the head to empty

    return True // send to caller the stack is empty

else return False // send to caller the stack is not empty

PUSH(object): // Insert an element to stack Always adding on first

object.next = S.head // make the header object second by adding next to received object

if S.head != NIL // if Stack is not empty

    S.head.prev = object

S.head = object

object.prev = NIL

POP(): // remove an element from stack, always removing the first

object = S.head

S.head = object.next

object.next.prev = S.head

return object

Circular doubly linked list

The next and previous are pointing the next element and the previous element respectively, This is for common doubly linked list, if the last elements next pointer is the header node than it is doubly linked list.

In the above data structure if the next pointed to the very first element then that is maintaining the circular doubly linked list,

first elements previous pointer pointing to the last element of the list.