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

Data structure question Someone answer already like this. If need to clarify or

ID: 3586226 • Letter: D

Question

Data structure question



Someone answer already like this. If need to clarify or edit, pls do it for me pls. Program to implement a circular link list.
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
/* structure containing a data part and link part */
struct node
{
int data ;
struct node * link ;
} ;
void addcirq ( struct node **, struct node **, int ) ;
int delcirq ( struct node **, struct node ** ) ;
void cirq_display ( struct node * ) ;
void main( )
{
struct node *front, *rear ;
front = rear = NULL ;
addcirq ( &front, &rear, 10 ) ;
addcirq ( &front, &rear, 17 ) ;
addcirq ( &front, &rear, 18 ) ;
addcirq ( &front, &rear, 5 ) ;
addcirq ( &front, &rear, 30 ) ;
addcirq ( &front, &rear, 15 ) ;
clrscr( ) ;
printf ( "Before deletion: " ) ;
cirq_display ( front ) ;
delcirq ( &front, &rear ) ;
delcirq ( &front, &rear ) ;
delcirq ( &front, &rear ) ;
printf ( " After deletion: " ) ;
cirq_display ( front ) ;
}
/* adds a new element at the end of queue */
void addcirq ( struct node **f, struct node **r, int item )
{
struct node *q ;
/* create new node */
q = malloc ( sizeof ( struct node ) ) ;
q -> data = item ;
/* if the queue is empty */
if ( *f == NULL )
*f = q ;
else
( *r ) -> link = q ;
*r = q ;
( *r ) -> link = *f ;
}
/* removes an element from front of queue */
int delcirq ( struct node **f, struct node **r )
{
struct node *q ;
int item ;
/* if queue is empty */
if ( *f == NULL )
printf ( "queue is empty" ) ;
else
{
if ( *f == *r )
{
item = ( *f ) -> data ;
free ( *f ) ;
*f = NULL ;
*r = NULL ;
}
else
{
/* delete the node */
q = *f ;
item = q -> data ;
*f = ( *f ) -> link ;
( *r ) -> link = *f ;
free ( q ) ;
}
return ( item ) ;
}
return NULL ;
}
/* displays whole of the queue */
void cirq_display ( struct node *f )
{
struct node *q = f, *p = NULL ;
/* traverse the entire linked list */
while ( q != p )
{
printf ( "%d ", q -> data ) ;
q = q -> link ;
p = f ;
}
}
Program to implement a circular link list.
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
/* structure containing a data part and link part */
struct node
{
int data ;
struct node * link ;
} ;
void addcirq ( struct node **, struct node **, int ) ;
int delcirq ( struct node **, struct node ** ) ;
void cirq_display ( struct node * ) ;
void main( )
{
struct node *front, *rear ;
front = rear = NULL ;
addcirq ( &front, &rear, 10 ) ;
addcirq ( &front, &rear, 17 ) ;
addcirq ( &front, &rear, 18 ) ;
addcirq ( &front, &rear, 5 ) ;
addcirq ( &front, &rear, 30 ) ;
addcirq ( &front, &rear, 15 ) ;
clrscr( ) ;
printf ( "Before deletion: " ) ;
cirq_display ( front ) ;
delcirq ( &front, &rear ) ;
delcirq ( &front, &rear ) ;
delcirq ( &front, &rear ) ;
printf ( " After deletion: " ) ;
cirq_display ( front ) ;
}
/* adds a new element at the end of queue */
void addcirq ( struct node **f, struct node **r, int item )
{
struct node *q ;
/* create new node */
q = malloc ( sizeof ( struct node ) ) ;
q -> data = item ;
/* if the queue is empty */
if ( *f == NULL )
*f = q ;
else
( *r ) -> link = q ;
*r = q ;
( *r ) -> link = *f ;
}
/* removes an element from front of queue */
int delcirq ( struct node **f, struct node **r )
{
struct node *q ;
int item ;
/* if queue is empty */
if ( *f == NULL )
printf ( "queue is empty" ) ;
else
{
if ( *f == *r )
{
item = ( *f ) -> data ;
free ( *f ) ;
*f = NULL ;
*r = NULL ;
}
else
{
/* delete the node */
q = *f ;
item = q -> data ;
*f = ( *f ) -> link ;
( *r ) -> link = *f ;
free ( q ) ;
}
return ( item ) ;
}
return NULL ;
}
/* displays whole of the queue */
void cirq_display ( struct node *f )
{
struct node *q = f, *p = NULL ;
/* traverse the entire linked list */
while ( q != p )
{
printf ( "%d ", q -> data ) ;
q = q -> link ;
p = f ;
}
}
Send me the new written code pls Page 1 of 6 Circular Linked List Assignment Overview A circular linked list is essentially a singly linked list in which the next pointer of the tail node is set to point to the head node of the linked list rather than set to nul. The first figure below shows a linked list as a singly linked list. The second figure below shows the singly linked list from the first figure as a circular linked list. In this assignment, you will write code for an implementation of a circular linked list 12 Head Tail Singly Linked List 12 Tail Circular Linked List

Explanation / Answer

public class CircularList {

private Node first;

private Node last;

private Node current;

private int size; // total items in the list

public CircularList getCurrent;

public CircularList() {

first = null;

last = null;

current = null;

size = 0;

}

public boolean isEmpty() {

return first == null;

}

public void step() {

current = current.next;

}

public Node getCurrent() {

return current;

}

public boolean get(int x) {

Node search = first;

int y = 0;

while (search.iData != x && y < count) {

search = search.next;

y++;

}

}

public boolean set(int x, E element ) {

Entry e = entry(index);

E oldVal = e.element;

e.element = element;

return oldVal;

}

public void add(int x) {

Node newNode = new Node(x);

if (isEmpty()) {

first = newNode;

current = first;

} else {

current.next = newNode;

}

newNode.next = first;

last = newNode;

step();

size++;

}

public void remove(int x) {

Node prev = first;

Node curr = first.next;

while (curr.iData != x) {

prev = curr;

curr = curr.next;

}

if (size == 1) {

first = null;

size--;

} else if (curr == first) {

prev.next = curr.next;

first = curr.next;

size--;

} else {

prev.next = curr.next;

size--;

}

}

public void displayList() {

int x = 0;

Node printer = first;

while (x < size) {

printer.displayNode();

printer = printer.next;

x++;

}

System.out.println("");

}

}