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

Make this java code C please, thanks. Edited: /\"static void main\" must be defi

ID: 3907272 • Letter: M

Question

Make this java code C please, thanks.
Edited:

/"static void main" must be defined in a public class import java.util. NoSuchElementException; public class SortedListRefBased private SortedNode head; private int numberOfItems; public SortedListRefBased() head null; /init head variable numberOfItemse; //init numitem public void createsortedList) head null; numberOfItems ; public boolean sortedIsEmpty ) return (numberOfItems0) public int sortedSize() return numberOfItems; public void sortedAdd (Object item) if (numberOfItems)//create new node as head head -new SortedNode(item); elset //find appropriate place to insert new node SortedNode prev null; SortedNode curr-head; while(currnull && ((Comparable)item).compareTo(curr.item e)( prev -curr; curr-curr.next; if(prevnull) //verify if previous node null //if is then insert new node at first head = new SortedNode(item, head); elset //if previous-null then isnert somewhere else prev.next- new SortedNode (item, curr); numberOfItems++;

Explanation / Answer

Hi,

Please find the code below :

#include<stdio.h>

#include<stdlib.h>

typedef struct node

{

int data;

struct node*next;

}node;

void sortedadd(node**s,int num)

{

node*temp;

if(*s==NULL||num<(*s)->data)

{

temp=(node*)malloc(sizeof(node));

temp->data=num;

temp->next=*s;

*s=temp;

}

else

{

temp=*s;

while(temp!=NULL)

{

if(temp->data<=num&&(temp->next==NULL || temp->next->data>num))

{

node*temp1=(node*)malloc(sizeof(node));

temp1->data=num;

temp1->next=temp->next;

temp->next=temp1;

return;

}

temp=temp->next;

}

}

}

void writesortedlist(node* s)

{

while(s!=NULL)

{

printf("%d ",s->data);

s=s->next;

}

}

int locateIndex(node* head,int value)

{

node *searchNode = head;

int flag = 0;

while(searchNode!=NULL)

{

if(searchNode->number==value)

{

printf("%d is present in this list. Memory address is %d ", value, searchNode);

flag = 1;

return value;

}

else

searchNode = searchNode->next;

}

if(flag==0)

printf("Item not found ");

return -1;

}

void delete_item(node* head, int value)

{

node *myNode = head, *previous=NULL;

int flag = 0;

while(myNode!=NULL)

{

if(myNode->number==value)

{

if(previous==NULL)

head = myNode->next;

else

previous->next = myNode->next;

printf("%d is deleted from list ", value);

flag = 1;

break;

}

previous = myNode;

myNode = myNode->next;

}

if(flag==0)

printf("Key not found! ");

}

void main()

{

node*n=NULL;

sortedadd(&n,45);

sortedadd(&n,35);

sortedadd(&n,50);

sortedadd(&n,30);

sortedadd(&n,40);

sortedadd(&n,50);

sortedadd(&n,45);

writesortedlist(n);

printf("Locate index %d",locateIndex(n,45));

delete_item(n,40);

delete_item(n,30);

delete_item(n,50);

writesortedlist(n);

}

Happy Coding :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote