Related questions
be in unsorted order in the file but they have to be placed in sorted order within the linked list.
The program should use a doubly linked list.
Each node in the doubly linked list should have the student’s name, a pointer to the next student, and a
pointer to the previous student. Here is a sample visual. The head points to the beginning of the list. The
tail points to the end of the list.
When inserting consider all the following conditions:
if(!head){ //no other nodes
}else if (strcmp(data, head->name)<0){ //smaller than head
}else if (strcmp(data, tail->name)>0){ //larger than tail
}else{ //somewhere in the middle
}
student may be at the head, the tail or in the middle
Below, you will find a sample of what the file looks like. Notice the names are in unsorted order but the
information placed in the linked list (above visual) is in sorted order. The name of the file should be
"input.txt".
In the text file, the word delete followed by a name, should delete the node with that specific student’s
name from the doubly linked list. If the name is not found, then nothing is deleted.
(NOTE: The above visual represents only the first three lines from the text file below.)
Jim
jill
John
delete jill
Bob
Jack
delete jim
At the end of the program, traverse through the contents of the linked list in both ascending and
descending order, using the doubly linked list, and write the contents into the file output.txt. For
example, given the above list, here is the sample display:
Bob
Jack
John
=============
John
Jack
Bob
- Do you have any suggestions about how I should start this lab?
A: Make sure that you draw out the nodes on a piece of paper so that you know exactly what is being connected to what. If you try to do this in your head, then more than likely, you will not do well.
- What do I do with duplicate names?
A: Ignore it.
- Do I need to use some sort of sort function to sort the nodes?
A: No, do not use any of the usual sorting
Once you create your node, start traversing through your linked list. A variable like curr will point to the node in your linked list that you are on. Compare the name in curr with the name in the newly created node. If the name in curr node is bigger, then you have found the spot to insert your node. If the name in curr node is smaller, then you continue to move to the next node in your list. If you have reached the end of the list and the name in curr node is smaller, then you have to insert at the end and update the tail. If the name in the curr node is bigger and you are at the beginning of your list, then you have a new head. If the names are the same, then you can just get out because you have a duplicate
if(!head){ //no other nodes
}else if (strcmp(data, head->name)<0){ //smaller than head
}else if (strcmp(data, tail->name)>0){ //larger than tail
}else{ //somewhere in the middle
Use a loop to traverse through the list to find the location of where you need to insert
}
- Can I use any of the built-in library for linked lists?
A: No, you create everything from scratch
- Can I read the items from the file into some other data structure, sort it and then recreate my linked list
A: No, you sort as you insert into your linked list.
- Can you provide a general pseudocode to get me started?
//you will not be reading the entire line but rather one word at a time
Loop through the file as long as there is something to read
Read word//reads first word which could be the word delete or a name
If the string==’delete’
Read word //this means that the next word is a name
Delete (word) //look for the node and delete it
Else
//the line just contained a name which means you insert
Insert (word)
Traverse() //Traverse through the list, display in ascending, descending order
Doubly contains head and tail as instance variables, delete,insert, traverseAsending, traverseDescnding methods. Since all variables are private, provide getter and setter methods
Node will contain value, prev, next as instance variables, Since all the variables will be private, provide getter and setter methods.
Driver will contain the main method which will contain the content from item 6 in this document
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
- In C++, write a program that reads in an array of type int. You may assume that there are fewer than 20 entries in the array. The output must be a two-column list. The first column is a list of the distinct array elements and the second column is the count of the number of occurences of each element.arrow_forwardIn c++ and please without the use of vectors. Thanks very much! A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use linear search. Modify the algorithm to output the count of how many comparisons were performed during the search, before it returns the index (or -1). int FindContact(ContactInfo contacts[], int size, string contactName) Ex: If the input is: 3 Joe 123-5432 Linda 983-4123...arrow_forwardWrite a function called find_duplicates which accepts one list as a parameter. This function needs to sort through the list passed to it and find values that are duplicated in the list. The duplicated values should be compiled into another list which the function will return. No matter how many times a word is duplicated, it should only be added once to the duplicates list. NB: Only write the function. Do not call it. For example: Test Result random_words = ("remember","snakes","nappy","rough","dusty","judicious","brainy","shop","light","straw","quickest", "adventurous","yielding","grandiose","replace","fat","wipe","happy","brainy","shop","light","straw", "quickest","adventurous","yielding","grandiose","motion","gaudy","precede","medical","park","flowers", "noiseless","blade","hanging","whistle","event","slip") print(find_duplicates(sorted(random_words))) ['adventurous', 'brainy', 'grandiose', 'light', 'quickest', 'shop', 'straw', 'yielding']...arrow_forward
- Using c++ Contact list: Binary Search A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use binary search. Modify the algorithm to output the count of how many comparisons using == with the contactName were performed during the search, before it returns the index (or -1). int FindContact(ContactInfo contacts[], int size, string contactName) Ex: If the input is: 3 Frank 867-5309 Joe...arrow_forwardThe function should be written in python language. Write a function called "zero_triples" to return all triples in a list of integers that sum to zero. You can assume the list won't contain any duplicates, and a triple should not use the same number more than once. [In]: zero_triples([1, 2, 4]) [Out]: [] [In]: zero_triples([-3, 1, 4, 2]) [Out]: [[1, 2, -3]] [In]: zero_triples([-9, 1, -3, 2, 4, 5, -4, -1]) [Out]: [[-9, 4, 5], [1, -3, 2], [-3, 4, -1], [5, -4, -1]]arrow_forwardPlease do it on c++ don't use stl function must read the instructionarrow_forward
- 5 partition_list (head) This is a little like split_list() from the Short problem, except that, instead of splitting the list into two by cutting it into the middle, you will now build two lists to return, using alternate values. The first value in the input list should be returned at the head of the first new list; the second value should be the head of the second list. Keep on alternating from there, putting one new value on the first list, and one on the second. (But remember that the length of the input list might be odd.) Example Suppose you have the following input list: 10 - 13 -> -1 -> 1000 - 0 It should return the following two lists: 10 1 0 13 -> 1000arrow_forwardIn pythonarrow_forwardin c++ please paste working code. the program should Input- Julia Lucas Mia -1 With an expected output of- Julia Lucas Mia Julia Mia Lucas Lucas Julia Mia Lucas Mia Julia Mia Julia Lucas Mia Lucas Juliaarrow_forward
- In Python Use the Design Recipe to write a function has_duplicates, which consumes a list and returns True if the list has any duplicate entries, False otherwise. Your function should return False if the list is emptyarrow_forwardPython Help Write a function equals(a,b) that returns true when the two lists a, and b have the same elements in the same order, and false otherwise.Write main() to call the function equals(a,b)arrow_forward
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY