SlideShare a Scribd company logo
Write the definition of the linkedListKeepLast function. (Please write the following in C,
Thank you)
The purpose of the function is to create a new linked list containing
the last node in each linked list in the hash table beginning with the first linked list.
The rest of the nodes are to be displayed to the screen, then returned to the heap.
Example:
If the user enters the following keys:
201, 102, 233, 567, 456, 654, 465, 645, quit
list at index 0 is empty
list at index 1 is not empty:
201
102
567
list at index 2 is not empty:
233
list at index 3 is empty
list at index 4 is not empty:
456
654
465
645
Deleted nodes:
--> at index 0:
--> at index 1: 201 102
--> at index 2:
--> at index 3:
--> at index 4: 456 654 465
The final linked list contains:
567
233
645
Written by:
*/
#include <stdio.h>
#include <stdlib.h> // malloc(), free(), exit()
#include <string.h>
#define NUMPOINTERS 5
typedef struct node STUDENTREC;
struct node
{
char id[10];
struct node *next;
};
// Function Declarations
int hash(char id[]);
STUDENTREC *insert(char id[],
STUDENTREC *student_body[],
int hashval);
void traverse(STUDENTREC *student_body[]);
void displayLL(STUDENTREC *list, char *description);
STUDENTREC *linkedListKeepLast(STUDENTREC *student_body[]);
int main (void)
{
STUDENTREC *student_body[NUMPOINTERS] = {NULL};
STUDENTREC *person;
STUDENTREC *endList;
char id[10];
int hashval;
printf(" ~*~ Hashing using collision resolution by chaining ~*~n");
printf("t Enter Student ID (or quit): ");
scanf("%s", id);
while(strcmp(id, "quit"))
{
hashval = hash(id);
person = insert(id, student_body, hashval);
if (person) // not NULL => duplicate
{
printf("Duplicate record!n");
}
printf("t Enter Student ID (or quit): ");
scanf("%s", id);
}
traverse(student_body);
endList = linkedListKeepLast(student_body);
displayLL(endList, "New List");
traverse(student_body);
return 0;
}
/*
The purpose of the function is to create a new linked list containing
the last node in each linked list in the hash table beginning with the first linked list.
The rest of the nodes are to be displayed to the screen, then returned to the heap.
*/
STUDENTREC *linkedListKeepLast(STUDENTREC *student_body[])
{
STUDENTREC *newList = NULL;
/* *********************************************************
Write your code here
Get the job done without calling other linked list functions
********************************************************* */
return newList;
}
/***************************************************
Hash Student ID by summing the cubes
of the ASCII value of characters and then take
the modulo of this sum.
*/
int hash(char id[])
{
long sum = 0;
while (*id) // != '0'
{
sum += *id * *id * *id;
id++;
}
return sum % NUMPOINTERS;
}
/***************************************************
Insert a new Social Security number into the
array of student records, at index equal to
hashvalue
*/
STUDENTREC *insert(char id[],
STUDENTREC *student_body[],
int hashval)
{
STUDENTREC **mover; // Use ** to write elegant code
mover = &student_body[hashval];
while (*mover)
{
if (strcmp(id,(*mover)->id) == 0) return *mover;
mover = &((*mover)->next);
}
if ((*mover = (STUDENTREC *) malloc(sizeof(STUDENTREC))) == NULL)
{
printf("Malloc error in insert!n");
exit(1);
}
strcpy((*mover)->id, id);
(*mover)->next = NULL; // set the link of the new node to NULL
printf("%s has been placed in the list at location %d.n", (*mover)->id, hashval);
return NULL;
}
/***************************************************
Traversing the lists in a hash table
*/
void traverse(STUDENTREC *student_body[])
{
int i;
// STUDENTREC **mover; // Use ** for fun and practice
// not needed for traverse
for (i = 0; i < NUMPOINTERS; i++)
{
printf("Contents of list %2dn", i);
printf("--------------------n");
// for (mover = &student_body[i]; *mover; mover = &(*mover)->next)
// { // &((*mover)->next)
// printf("%sn", (*mover)->ss);
// }
displayLL(student_body[i], NULL);
printf("n");
}
}
/***************************************************
Traversing a linked list
*/
void displayLL(STUDENTREC *list, char *description)
{
if (list) // != NULL
{
if (description) // != NULL
{
printf ("%sn", description);
printf("--------------------n");
}
STUDENTREC **mover; // Use ** for fun and practice
// not needed for traverse
for (mover = &list; *mover; mover = &(*mover)->next)
{ // &((*mover)->next)
printf("%sn", (*mover)->id);
}
}
else
printf ("Empty!");
printf("n");
}
/*
~*~ Hashing using collision resolution by chaining ~*~
Enter Student ID (or quit): 201
201 has been placed in the list at location 1.
Enter Student ID (or quit): 102
102 has been placed in the list at location 1.
Enter Student ID (or quit): 233
233 has been placed in the list at location 2.
Enter Student ID (or quit): 567
567 has been placed in the list at location 1.
Enter Student ID (or quit): 456
456 has been placed in the list at location 4.
Enter Student ID (or quit): 654
654 has been placed in the list at location 4.
Enter Student ID (or quit): 465
465 has been placed in the list at location 4.
Enter Student ID (or quit): 645
645 has been placed in the list at location 4.
Enter Student ID (or quit): quit
Contents of list 0
--------------------
Empty!
Contents of list 1
--------------------
201
102
567
Contents of list 2
--------------------
233
Contents of list 3
--------------------
Empty!
Contents of list 4
--------------------
456
654
465
645
Deleted nodes:
--> at index 0:
--> at index 1: 201 102
--> at index 2:
--> at index 3:
--> at index 4: 456 654 465
New List
--------------------
567
233
645
Contents of list 0
--------------------
Empty!
Contents of list 1
--------------------
Empty!
Contents of list 2
--------------------
Empty!
Contents of list 3
--------------------
Empty!
Contents of list 4
--------------------
Empty!
*/

More Related Content

Similar to Write the definition of the linkedListKeepLast function- (Please write.docx

package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
amazing2001
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
mallik3000
 
Modify the Simple lexer program given in the link below to .pdf
Modify the Simple lexer program given in the link below to .pdfModify the Simple lexer program given in the link below to .pdf
Modify the Simple lexer program given in the link below to .pdf
adityaenterprise32
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
clarkjanyce
 
C++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdfC++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdf
saradashata
 
Write a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfWrite a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdf
thangarajarivukadal
 
Background Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfBackground Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdf
aaseletronics2013
 
write recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdfwrite recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdf
arpitcomputronics
 
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docxPlease code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
cgraciela1
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
afgt2012
 
Stack queue
Stack queueStack queue
Stack queue
James Wong
 
Stack queue
Stack queueStack queue
Stack queue
Fraboni Ec
 
Stack queue
Stack queueStack queue
Stack queue
Hoang Nguyen
 
How to build a Linked List that can insert any type of data. For exa.pdf
How to build a Linked List that can insert any type of data. For exa.pdfHow to build a Linked List that can insert any type of data. For exa.pdf
How to build a Linked List that can insert any type of data. For exa.pdf
arpittradersjdr
 
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
honey725342
 

Similar to Write the definition of the linkedListKeepLast function- (Please write.docx (20)

package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
 
Modify the Simple lexer program given in the link below to .pdf
Modify the Simple lexer program given in the link below to .pdfModify the Simple lexer program given in the link below to .pdf
Modify the Simple lexer program given in the link below to .pdf
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
 
C++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdfC++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdf
 
Write a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfWrite a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdf
 
Background Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfBackground Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdf
 
write recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdfwrite recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdf
 
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docxPlease code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
How to build a Linked List that can insert any type of data. For exa.pdf
How to build a Linked List that can insert any type of data. For exa.pdfHow to build a Linked List that can insert any type of data. For exa.pdf
How to build a Linked List that can insert any type of data. For exa.pdf
 
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
 

More from delicecogupdyke

You have been learning about Urie Bronfenbrenner this week- Let's mak.docx
You have been learning about Urie Bronfenbrenner this week-  Let's mak.docxYou have been learning about Urie Bronfenbrenner this week-  Let's mak.docx
You have been learning about Urie Bronfenbrenner this week- Let's mak.docx
delicecogupdyke
 
You encounter a flat green organism growing on a rock with no obvious.docx
You encounter a flat green organism growing on a rock with no obvious.docxYou encounter a flat green organism growing on a rock with no obvious.docx
You encounter a flat green organism growing on a rock with no obvious.docx
delicecogupdyke
 
You are the PR specialist for St- John's Ambulance- The organization w.docx
You are the PR specialist for St- John's Ambulance- The organization w.docxYou are the PR specialist for St- John's Ambulance- The organization w.docx
You are the PR specialist for St- John's Ambulance- The organization w.docx
delicecogupdyke
 
You are the CFO of a large academic medical center and your organizati (1).docx
You are the CFO of a large academic medical center and your organizati (1).docxYou are the CFO of a large academic medical center and your organizati (1).docx
You are the CFO of a large academic medical center and your organizati (1).docx
delicecogupdyke
 
You are on a field trip with your bio class- Your water sample from a.docx
You are on a field trip with your bio class- Your water sample from a.docxYou are on a field trip with your bio class- Your water sample from a.docx
You are on a field trip with your bio class- Your water sample from a.docx
delicecogupdyke
 
You are fortunate to travel to a tropical forest- You find an insect o.docx
You are fortunate to travel to a tropical forest- You find an insect o.docxYou are fortunate to travel to a tropical forest- You find an insect o.docx
You are fortunate to travel to a tropical forest- You find an insect o.docx
delicecogupdyke
 
You are a Government employee working in the Human Resources departmen.docx
You are a Government employee working in the Human Resources departmen.docxYou are a Government employee working in the Human Resources departmen.docx
You are a Government employee working in the Human Resources departmen.docx
delicecogupdyke
 
You are a genetic cownselar- A single mother cnmes to vou- where both.docx
You are a genetic cownselar- A single mother cnmes to vou- where both.docxYou are a genetic cownselar- A single mother cnmes to vou- where both.docx
You are a genetic cownselar- A single mother cnmes to vou- where both.docx
delicecogupdyke
 
Write the following report that can be a powerpoint presentation-The g.docx
Write the following report that can be a powerpoint presentation-The g.docxWrite the following report that can be a powerpoint presentation-The g.docx
Write the following report that can be a powerpoint presentation-The g.docx
delicecogupdyke
 
Write two functions using the Front and Back Linear Search algorithms-.docx
Write two functions using the Front and Back Linear Search algorithms-.docxWrite two functions using the Front and Back Linear Search algorithms-.docx
Write two functions using the Front and Back Linear Search algorithms-.docx
delicecogupdyke
 
xpected to grow geometrically- (Assume that interactions ith other spe.docx
xpected to grow geometrically- (Assume that interactions ith other spe.docxxpected to grow geometrically- (Assume that interactions ith other spe.docx
xpected to grow geometrically- (Assume that interactions ith other spe.docx
delicecogupdyke
 
Write the pseudocode for Python for the following- from Celsius to Fah.docx
Write the pseudocode for Python for the following- from Celsius to Fah.docxWrite the pseudocode for Python for the following- from Celsius to Fah.docx
Write the pseudocode for Python for the following- from Celsius to Fah.docx
delicecogupdyke
 
Write SQL commands that convert the Database schema to Tables with the.docx
Write SQL commands that convert the Database schema to Tables with the.docxWrite SQL commands that convert the Database schema to Tables with the.docx
Write SQL commands that convert the Database schema to Tables with the.docx
delicecogupdyke
 
write the adjusting entries for following Given Data-.docx
write the adjusting entries for following    Given Data-.docxwrite the adjusting entries for following    Given Data-.docx
write the adjusting entries for following Given Data-.docx
delicecogupdyke
 
Write python code to collect 1000 posts from Twitter- or Facebook- or.docx
Write python code to collect 1000 posts from Twitter- or Facebook- or.docxWrite python code to collect 1000 posts from Twitter- or Facebook- or.docx
Write python code to collect 1000 posts from Twitter- or Facebook- or.docx
delicecogupdyke
 
write one to two paragraphs on the significance about Jati Explain how.docx
write one to two paragraphs on the significance about Jati Explain how.docxwrite one to two paragraphs on the significance about Jati Explain how.docx
write one to two paragraphs on the significance about Jati Explain how.docx
delicecogupdyke
 
Write in C++ Calculate the mean of a vector of floating point numbers.docx
Write in C++ Calculate the mean of a vector of floating point numbers.docxWrite in C++ Calculate the mean of a vector of floating point numbers.docx
Write in C++ Calculate the mean of a vector of floating point numbers.docx
delicecogupdyke
 
Write down the code that will count the number of clicks for a LIKE bu.docx
Write down the code that will count the number of clicks for a LIKE bu.docxWrite down the code that will count the number of clicks for a LIKE bu.docx
Write down the code that will count the number of clicks for a LIKE bu.docx
delicecogupdyke
 
Write declarations for variables p1 and p2 whose values will be addres.docx
Write declarations for variables p1 and p2 whose values will be addres.docxWrite declarations for variables p1 and p2 whose values will be addres.docx
Write declarations for variables p1 and p2 whose values will be addres.docx
delicecogupdyke
 
Write an example of an organization which has formed an inter-organiza.docx
Write an example of an organization which has formed an inter-organiza.docxWrite an example of an organization which has formed an inter-organiza.docx
Write an example of an organization which has formed an inter-organiza.docx
delicecogupdyke
 

More from delicecogupdyke (20)

You have been learning about Urie Bronfenbrenner this week- Let's mak.docx
You have been learning about Urie Bronfenbrenner this week-  Let's mak.docxYou have been learning about Urie Bronfenbrenner this week-  Let's mak.docx
You have been learning about Urie Bronfenbrenner this week- Let's mak.docx
 
You encounter a flat green organism growing on a rock with no obvious.docx
You encounter a flat green organism growing on a rock with no obvious.docxYou encounter a flat green organism growing on a rock with no obvious.docx
You encounter a flat green organism growing on a rock with no obvious.docx
 
You are the PR specialist for St- John's Ambulance- The organization w.docx
You are the PR specialist for St- John's Ambulance- The organization w.docxYou are the PR specialist for St- John's Ambulance- The organization w.docx
You are the PR specialist for St- John's Ambulance- The organization w.docx
 
You are the CFO of a large academic medical center and your organizati (1).docx
You are the CFO of a large academic medical center and your organizati (1).docxYou are the CFO of a large academic medical center and your organizati (1).docx
You are the CFO of a large academic medical center and your organizati (1).docx
 
You are on a field trip with your bio class- Your water sample from a.docx
You are on a field trip with your bio class- Your water sample from a.docxYou are on a field trip with your bio class- Your water sample from a.docx
You are on a field trip with your bio class- Your water sample from a.docx
 
You are fortunate to travel to a tropical forest- You find an insect o.docx
You are fortunate to travel to a tropical forest- You find an insect o.docxYou are fortunate to travel to a tropical forest- You find an insect o.docx
You are fortunate to travel to a tropical forest- You find an insect o.docx
 
You are a Government employee working in the Human Resources departmen.docx
You are a Government employee working in the Human Resources departmen.docxYou are a Government employee working in the Human Resources departmen.docx
You are a Government employee working in the Human Resources departmen.docx
 
You are a genetic cownselar- A single mother cnmes to vou- where both.docx
You are a genetic cownselar- A single mother cnmes to vou- where both.docxYou are a genetic cownselar- A single mother cnmes to vou- where both.docx
You are a genetic cownselar- A single mother cnmes to vou- where both.docx
 
Write the following report that can be a powerpoint presentation-The g.docx
Write the following report that can be a powerpoint presentation-The g.docxWrite the following report that can be a powerpoint presentation-The g.docx
Write the following report that can be a powerpoint presentation-The g.docx
 
Write two functions using the Front and Back Linear Search algorithms-.docx
Write two functions using the Front and Back Linear Search algorithms-.docxWrite two functions using the Front and Back Linear Search algorithms-.docx
Write two functions using the Front and Back Linear Search algorithms-.docx
 
xpected to grow geometrically- (Assume that interactions ith other spe.docx
xpected to grow geometrically- (Assume that interactions ith other spe.docxxpected to grow geometrically- (Assume that interactions ith other spe.docx
xpected to grow geometrically- (Assume that interactions ith other spe.docx
 
Write the pseudocode for Python for the following- from Celsius to Fah.docx
Write the pseudocode for Python for the following- from Celsius to Fah.docxWrite the pseudocode for Python for the following- from Celsius to Fah.docx
Write the pseudocode for Python for the following- from Celsius to Fah.docx
 
Write SQL commands that convert the Database schema to Tables with the.docx
Write SQL commands that convert the Database schema to Tables with the.docxWrite SQL commands that convert the Database schema to Tables with the.docx
Write SQL commands that convert the Database schema to Tables with the.docx
 
write the adjusting entries for following Given Data-.docx
write the adjusting entries for following    Given Data-.docxwrite the adjusting entries for following    Given Data-.docx
write the adjusting entries for following Given Data-.docx
 
Write python code to collect 1000 posts from Twitter- or Facebook- or.docx
Write python code to collect 1000 posts from Twitter- or Facebook- or.docxWrite python code to collect 1000 posts from Twitter- or Facebook- or.docx
Write python code to collect 1000 posts from Twitter- or Facebook- or.docx
 
write one to two paragraphs on the significance about Jati Explain how.docx
write one to two paragraphs on the significance about Jati Explain how.docxwrite one to two paragraphs on the significance about Jati Explain how.docx
write one to two paragraphs on the significance about Jati Explain how.docx
 
Write in C++ Calculate the mean of a vector of floating point numbers.docx
Write in C++ Calculate the mean of a vector of floating point numbers.docxWrite in C++ Calculate the mean of a vector of floating point numbers.docx
Write in C++ Calculate the mean of a vector of floating point numbers.docx
 
Write down the code that will count the number of clicks for a LIKE bu.docx
Write down the code that will count the number of clicks for a LIKE bu.docxWrite down the code that will count the number of clicks for a LIKE bu.docx
Write down the code that will count the number of clicks for a LIKE bu.docx
 
Write declarations for variables p1 and p2 whose values will be addres.docx
Write declarations for variables p1 and p2 whose values will be addres.docxWrite declarations for variables p1 and p2 whose values will be addres.docx
Write declarations for variables p1 and p2 whose values will be addres.docx
 
Write an example of an organization which has formed an inter-organiza.docx
Write an example of an organization which has formed an inter-organiza.docxWrite an example of an organization which has formed an inter-organiza.docx
Write an example of an organization which has formed an inter-organiza.docx
 

Recently uploaded

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 

Recently uploaded (20)

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 

Write the definition of the linkedListKeepLast function- (Please write.docx

  • 1. Write the definition of the linkedListKeepLast function. (Please write the following in C, Thank you) The purpose of the function is to create a new linked list containing the last node in each linked list in the hash table beginning with the first linked list. The rest of the nodes are to be displayed to the screen, then returned to the heap. Example: If the user enters the following keys: 201, 102, 233, 567, 456, 654, 465, 645, quit list at index 0 is empty list at index 1 is not empty: 201 102 567 list at index 2 is not empty: 233 list at index 3 is empty list at index 4 is not empty: 456 654 465 645 Deleted nodes: --> at index 0: --> at index 1: 201 102
  • 2. --> at index 2: --> at index 3: --> at index 4: 456 654 465 The final linked list contains: 567 233 645 Written by: */ #include <stdio.h> #include <stdlib.h> // malloc(), free(), exit() #include <string.h> #define NUMPOINTERS 5 typedef struct node STUDENTREC; struct node { char id[10]; struct node *next; }; // Function Declarations int hash(char id[]); STUDENTREC *insert(char id[], STUDENTREC *student_body[],
  • 3. int hashval); void traverse(STUDENTREC *student_body[]); void displayLL(STUDENTREC *list, char *description); STUDENTREC *linkedListKeepLast(STUDENTREC *student_body[]); int main (void) { STUDENTREC *student_body[NUMPOINTERS] = {NULL}; STUDENTREC *person; STUDENTREC *endList; char id[10]; int hashval; printf(" ~*~ Hashing using collision resolution by chaining ~*~n"); printf("t Enter Student ID (or quit): "); scanf("%s", id); while(strcmp(id, "quit")) { hashval = hash(id); person = insert(id, student_body, hashval); if (person) // not NULL => duplicate { printf("Duplicate record!n"); } printf("t Enter Student ID (or quit): ");
  • 4. scanf("%s", id); } traverse(student_body); endList = linkedListKeepLast(student_body); displayLL(endList, "New List"); traverse(student_body); return 0; } /* The purpose of the function is to create a new linked list containing the last node in each linked list in the hash table beginning with the first linked list. The rest of the nodes are to be displayed to the screen, then returned to the heap. */ STUDENTREC *linkedListKeepLast(STUDENTREC *student_body[]) { STUDENTREC *newList = NULL; /* ********************************************************* Write your code here Get the job done without calling other linked list functions ********************************************************* */ return newList; } /***************************************************
  • 5. Hash Student ID by summing the cubes of the ASCII value of characters and then take the modulo of this sum. */ int hash(char id[]) { long sum = 0; while (*id) // != '0' { sum += *id * *id * *id; id++; } return sum % NUMPOINTERS; } /*************************************************** Insert a new Social Security number into the array of student records, at index equal to hashvalue */ STUDENTREC *insert(char id[], STUDENTREC *student_body[], int hashval) {
  • 6. STUDENTREC **mover; // Use ** to write elegant code mover = &student_body[hashval]; while (*mover) { if (strcmp(id,(*mover)->id) == 0) return *mover; mover = &((*mover)->next); } if ((*mover = (STUDENTREC *) malloc(sizeof(STUDENTREC))) == NULL) { printf("Malloc error in insert!n"); exit(1); } strcpy((*mover)->id, id); (*mover)->next = NULL; // set the link of the new node to NULL printf("%s has been placed in the list at location %d.n", (*mover)->id, hashval); return NULL; } /*************************************************** Traversing the lists in a hash table */ void traverse(STUDENTREC *student_body[]) { int i;
  • 7. // STUDENTREC **mover; // Use ** for fun and practice // not needed for traverse for (i = 0; i < NUMPOINTERS; i++) { printf("Contents of list %2dn", i); printf("--------------------n"); // for (mover = &student_body[i]; *mover; mover = &(*mover)->next) // { // &((*mover)->next) // printf("%sn", (*mover)->ss); // } displayLL(student_body[i], NULL); printf("n"); } } /*************************************************** Traversing a linked list */ void displayLL(STUDENTREC *list, char *description) { if (list) // != NULL { if (description) // != NULL {
  • 8. printf ("%sn", description); printf("--------------------n"); } STUDENTREC **mover; // Use ** for fun and practice // not needed for traverse for (mover = &list; *mover; mover = &(*mover)->next) { // &((*mover)->next) printf("%sn", (*mover)->id); } } else printf ("Empty!"); printf("n"); } /* ~*~ Hashing using collision resolution by chaining ~*~ Enter Student ID (or quit): 201 201 has been placed in the list at location 1. Enter Student ID (or quit): 102 102 has been placed in the list at location 1. Enter Student ID (or quit): 233 233 has been placed in the list at location 2. Enter Student ID (or quit): 567
  • 9. 567 has been placed in the list at location 1. Enter Student ID (or quit): 456 456 has been placed in the list at location 4. Enter Student ID (or quit): 654 654 has been placed in the list at location 4. Enter Student ID (or quit): 465 465 has been placed in the list at location 4. Enter Student ID (or quit): 645 645 has been placed in the list at location 4. Enter Student ID (or quit): quit Contents of list 0 -------------------- Empty! Contents of list 1 -------------------- 201 102 567 Contents of list 2 -------------------- 233 Contents of list 3 --------------------
  • 10. Empty! Contents of list 4 -------------------- 456 654 465 645 Deleted nodes: --> at index 0: --> at index 1: 201 102 --> at index 2: --> at index 3: --> at index 4: 456 654 465 New List -------------------- 567 233 645 Contents of list 0 -------------------- Empty! Contents of list 1 --------------------
  • 11. Empty! Contents of list 2 -------------------- Empty! Contents of list 3 -------------------- Empty! Contents of list 4 -------------------- Empty! */