Question

Suppose a linked list (implemented using the array implementation) is ordered by the ABC123 ID and a node is represented by the following Node definition: #define MAX NODES 100 tvpedef struct shac. szAbc1231d[7]: double dGPA; int iNext: Node; Node nodeMIMAX NODES]; int iHead; int ifind, iBest, iPrecedes; // assume the linked list has been populated with values and // iHead points to the first node in that array. // practice problem #1- sample invocation iFind searchLL(nodeM, iHead, XYZ321, &iprecedes): if (iFind1) printf.(Not found\n); 1. Modify the searchLL function from class to be passed an ABC123 ID and find the specified student in the linked list. If it is found, return the subscript to that student. If it is not found, return LL_NULL. Also, return (via the parameter list) the subscript to the node that precedes that node. If there isnt a preceding node, this should be LL NULL



0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE:

#include<stdio.h>
#define MAX_NODES 100
#define LL_NULL -1
typedef struct
{
char szAbc123Id[7];
double dGPA;
int iNext;
}Node;
Node nodeM[MAX_NODES];
int iHead;
int iFind,iBest,iPrecedes;
int comp(char a[],char b[])
{
int i=0;
for(i=0;i<6;i++)
if(a[i]!=b[i])
return -1;
return 0;

}
int searchLL(Node nodeM[],int iHead, char c[7],int *iPrecedes)
{
int i,*j;
int l=0;
i=iHead;
j=LL_NULL;
while(1)
{
if(comp(nodeM[i].szAbc123Id,c)==0)
return i;
else
{
*j=i;
iPrecedes=j;
i=nodeM[i].iNext;
}
if(l==1)
break;
if(nodeM[i].iNext==LL_NULL)
l=1;
}
return LL_NULL;
}
void main()
{

iFind = searchLL(nodeM,iHead,"XYZ321",&iPrecedes);
if(iFind==-1)
printf("Not Found\n");
}

SCREENSHOTS:
Blocks 17.1 Eile Edit Yiew Search Project Build Debug Fortran wmith Iools Tools Plugins DoxyBlocks Settings Help <global> sea

Add a comment
Know the answer?
Add Answer to:
Suppose a linked list (implemented using the array implementation) is ordered by the ABC123 ID and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Suppose a linked list (implemented using pointers) is ordered by the ABC123 ID and a node...

    Suppose a linked list (implemented using pointers) is ordered by the ABC123 ID and a node is represented by the following Node definition: typedef struct char szAbc123Id [7]; double dGPA; Student; tvpedef struct Node // This is different from last week since // student is in the node instead of // directly containing szAbc123Id and dGpa. Student student; struct Node *pNext; Node, Node *pHead; Node *pFind, *pworst, *pPrecedes;

  • C++ help 0.1. An ordered linked list of characters has been constructed using the array-based implementation....

    C++ help 0.1. An ordered linked list of characters has been constructed using the array-based implementation. The following diagram shows the current contents of the array that stores the elements in an alphabetical order in the linked list and an available pool of nodes. Node data next о е м и р first = 5 - п free = 6 о у 1) Write in order the contents (data) of the nodes of the linked list pointed to by first....

  • Using the provided table interface table.h and the sample linked list code linkedList.c, complete an implementation...

    Using the provided table interface table.h and the sample linked list code linkedList.c, complete an implementation of the Table ADT. Make sure that you apply the concepts of design by contract (DbC) to your implementation. Once you have fully implemented the table, create a main.c file that implements a testing framework for your table. Your table implementation must ensure that values inserted are unique, and internally sorted within a linked list. table.h #ifndef _TABLE_H #define _TABLE_H //----------------------------------------------------------------------------- // CONSTANTS AND...

  • You are given a pointer to a singly linked list. The singly linked list has cycles...

    You are given a pointer to a singly linked list. The singly linked list has cycles due to a programming error. Write a C program to detect whether the linked list has cycles without storing all the pointers to the nodes. The function detect_cycles should return 1 when a cycle is found and 0 when there are no cycles. Your code should handle all corner cases carefully and should not cause segmentation fault. Figure shows various examples of cycles for...

  • In this project, you will be writing an object that implements an ordered linked list with...

    In this project, you will be writing an object that implements an ordered linked list with operator overload support for insertions and deletions. The specification for the list object will be provided upfront and you must design an implementation that supports the provided specification. In addition, you will be given a list of tasks that should be performed. CIS 221 Programming II C++ Programming Project operator overloaded ordered Linked List object Overview In this assignment, the student will write a...

  • 1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show...

    1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show the Linked List after the following commands are executed: Stack myStack = new Stack(); myStack.push(20); myStack.push(40); myStack.pop(); myStack.push(60); myStack.push(80); 2)If the same commands were used but the Stack was implemented with an Array with maximum size of 10, show what the array would look like after all these commands are executed. Assume O(1) implementation of push and pop here as well. 3)Given a Queue...

  • C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use...

    C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use to implement your program can have a profound impact on it's overall performance. A poorly written program will often need much more RAM and CPU time then a well-written implementation. One of the most basic data structure questions revolves around the difference between an array and a linked list. After you finish this assignment you should have a firm understanding of their operation. Problem...

  • I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas....

    I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas. public class Node ! int id; Node next: public Node (int id) ( this.id id: Write program codes for the traditional: 1) append int id), prepend(int id), removeFirstNodeO. displayAlINodesO, and findById(int id) operations for a singly linked list 2) pushint id), pop), peek0, displayAllNodes0 operations for a stack 3) enQueue(int id), deQueuel), displayAINodes() operations for a gueue Please make sure that you declare separate...

  • implement a doubly-linked list in C. Each node in the linked list should contain a string,...

    implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...

  • Programming in C: I am trying to modify this linked list to be doubly linked list....

    Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT