SlideShare a Scribd company logo
For any help regarding C Homework Help
visit : - https://www.programminghomeworkhelp.com/ ,
Email :- support@programminghomeworkhelp.com or
call us at :- +1 678 648 4277
C Homework Help
Linked List using C Homework Help
The problems:
PS3.0: Node and List
Before you can work on the list operations, you'll need to create both a node and
a list. The node should be responsible for node-y things, and the list for list-y
things, in other words, they won't know much about each other. The list will
accept a filled-in node and add it to the list.
The node should be a struct, and it looks about the same as the one we've seen
in lectures:
typedef struct node { int value; node* next;
}
Here are the signatures for both node's and list's functions. Note that this is just
the starting set of functions; each problem will require you to (possibly) add new
functions to one or both of list and node.
For nodes:
programminghomeworkhelp.com
node* createNode(int value); //Create a new node with a given value
For lists:
bool addNode(node* node); //Add a node to the list node* findNode(int
value); //Find a node in the list bool deleteNode (node*
node); //Delete a node in the list
void printList(void); //Print the values in the list
The returned boolean values should indicate success or failure of the
operation.
PS3.1 Add a set of nodes (in main.c)
Create a singly linked list from this array:
[89, 39, 18, 96, 71, 25, 2, 55, 60, -8, 9, 42, 69, 96, 24]
Read each value in turn and call createNode, then addNode. Nodes must be
dynamically allocated using malloc().
Print the list.
programminghomeworkhelp.com
PS3.2 Delete the largest nodes
From main, ask the list to delete all of the nodes that contain the largest value
in the list.
The signature for this function will be similar to
void deleteLargest(void);
On the list side, deleteLargest should call an internal list function to find *all*
nodes that contain
the same largest value (there should be more than one), and then call the
internal deleteNode function to delete all of the nodes found. Hint: You can use
an array to collect the largest nodes as you find them.
Print the list.
PS3.3 Count the nodes in the list
From main, ask the list to return the number of nodes in the list, and print the
value.
programminghomeworkhelp.com
Solution:
List:
#include <stdio.h>
PS3.4 Sort the list
From main, ask the list to sort itself. Use a bubble-sort algorithm:
•Starting from the top of the list, compare the value in the first node with
the value in the second node
•If the value in the second node is smaller, swap the two nodes, otherwise
leave them in place
•Move to the second node and compare its value with the third node,
swapping them if necessary
•Repeat this until you've reached the end of the list
•Next, go back to the top and do it all over again
•The list is sorted when you walk the entire list from top to bottom and do
not perform any swaps
The list should be sorted in-place. In other words, don't use a second list.
Print the list
programminghomeworkhelp.com
#include <stdlib.h>
#include "list.h"
node *head = NULL;
//Add a node to the list bool addNode(node *new_node)
{
if (head == NULL)
{
// This is add node to empty list. Just assign head to new node
head = new_node;
}
else
{
// This is list with elment. Try to add new node to end of list
node *current_node = head;
while (current_node->next != NULL)
{
programminghomeworkhelp.com
current_node = current_node->next;
}
// Now we are in end of list. Just add next to current
node current_node->next = new_node;
}
return true;
}
//Find a node in the list node* findNode(int value)
{
node *current_node = head; while (current_node !=
NULL)
{
if (current_node->value == value)
{
// If this node contain value is the same. Just return it
return current_node;
}
// Go the next node for next check current_node =
current_node->next;
}
// Go to end of node. And we can not found anything.
Just return null. return NULL;
programminghomeworkhelp.com
}
//Delete a node in the list bool deleteNode(node *del_node)
{
if (head == NULL)
{
// Current list is empty. We can not delete any more return
false;
}
else if (head->value == del_node->value)
{
// If this is delete the head node. node *tmp = head->next;
free(head);
head = tmp; return true;
}
else
{
// If this is delete the middle node node *current_node =
head;
node *prev_node = NULL;
while (current_node != NULL)
{
if (current_node->value == del_node->value)
programminghomeworkhelp.com
{
// Find the node to be delete. prev_node->next =
current_node->next; free(current_node);
return true;
}
// If this is not a node delete. Just move to next node
for
checking.
prev_node = current_node; current_node = current_node-
>next;
}
}
// Can not found any node in list for remove. return false;
}
//Print the values in the list void printList(void)
{
node *current_node = head; while (current_node)
{
printf("%d ", current_node->value); current_node = current_node-
>next;
programminghomeworkhelp.com
}
printf("n");
}
void deleteLargest(void)
{
// First step is find the largest node int largest_value =
head->value;
node *current_node = head->next; while (current_node)
{
if (current_node->value > largest_value)
{
// If found new node largest. Just keep track it.
largest_value = current_node->value;
}
// Move to next node for check current_node =
current_node->next;
}
// Now try to delete all node largest node. node
*del_node = malloc(sizeof(node)); del_node->value =
largest_value;
programminghomeworkhelp.com
del_node->next = NULL;
// Loop until no more largest value in node. while
(findNode(largest_value) != NULL)
{
deleteNode(del_node);
}
free(del_node);
}
int count(void) { int cnt = 0;
node* current_node = head; while(current_node) {
cnt++;
current_node = current_node->next;
}
return cnt;
}
void sort(void) { if(head == NULL) {
// Don't need to sort the empty list
return;
} else
{
programminghomeworkhelp.com
if(compare_node->value < current_node->value) {
// We need to swap 2 node
int tmp_value = current_node->value;
current_node->value = compare_node->value;
compare_node->value = tmp_value;
}
compare_node = compare_node->next;
}
current_node = current_node->next;
}
}
}
Main:
#include <stdio.h>
#include <stdlib.h>
#include "node.h"
#include "list.h"
int main(int argc, char** argv) {
// PS3.1 - Add a set of nodes.
node* current_node = head; node*
compare_node = NULL; while(current_node)
{
compare_node = current_node->next;
while(compare_node) {
programminghomeworkhelp.com
// Create a signly linked list from this array. [89, 39,
18, 96, 71,
25, 2, 55, 60, -8, 9, 42, 69, 96, 24]
int array[15] = {89, 39, 18, 96, 71, 25, 2, 55, 60, -8,
9, 42, 69, 96,
24};
for(int i = 0; i < 15; i++) {
node* new_node = createNode(array[i]);
addNode(new_node);
}
// Print list
printf("PS3.1 - List after add: "); printList();
printf("========================================
===n");
// PS3.2 Delete the largest nodes
printf("PS3.2 - Try to delete the largest node.n");
deleteLargest();
printf("List after delete: "); printList();
printf("========================================
===n");
// PS3.3 - Count the nodes in the list printf("PS3.3 -
Count the nodes in the listn"); int list_size = count();
printf("Count nodes in list: %dn", list_size);
programminghomeworkhelp.com
//Create a new node with a given value node* createNode(int
value)
{
// Allocate a new node
node *new_node = (node*) malloc(sizeof(node)); if (new_node)
{
// Check the allocated is successfull new_node->value = value;
new_node->next = NULL;
}
return new_node;
}
// PS3.4 - Sort the list printf("PS3.4 - List after sort: ");
sort();
printList();
// j o h n n y t u o t - g m a i l - c o m return 0;
}
Node:
#include <stdio.h>
#include <stdlib.h>
#include "node.h"
programminghomeworkhelp.com

More Related Content

What's hot

Linked list
Linked listLinked list
Linked list
Ajharul Abedeen
 
LINKED LISTS
LINKED LISTSLINKED LISTS
LINKED LISTS
Dhrthi Nanda
 
linked list
linked listlinked list
linked list
Abbott
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
Akila Krishnamoorthy
 
Linked lists
Linked listsLinked lists
Linkedlist
LinkedlistLinkedlist
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
Adam Mukharil Bachtiar
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
Adam Mukharil Bachtiar
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
Linked list
Linked listLinked list
Linked list
Trupti Agrawal
 
Singly & Circular Linked list
Singly & Circular Linked listSingly & Circular Linked list
Singly & Circular Linked list
Khulna University of Engineering & Tecnology
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
Prof Ansari
 
Link list
Link listLink list
Link list
Syeda Javeria
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
Muhazzab Chouhadry
 
Arrays
ArraysArrays

What's hot (20)

Linked list
Linked listLinked list
Linked list
 
LINKED LISTS
LINKED LISTSLINKED LISTS
LINKED LISTS
 
linked list
linked listlinked list
linked list
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Linked lists
Linked listsLinked lists
Linked lists
 
Linked list
Linked listLinked list
Linked list
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
Linked list
Linked list Linked list
Linked list
 
11 15 (doubly linked list)
11 15 (doubly linked list)11 15 (doubly linked list)
11 15 (doubly linked list)
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Linked list
Linked listLinked list
Linked list
 
Singly & Circular Linked list
Singly & Circular Linked listSingly & Circular Linked list
Singly & Circular Linked list
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
 
Link list
Link listLink list
Link list
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
 
Arrays
ArraysArrays
Arrays
 

Similar to C Homework Help

C Exam Help
C Exam Help C Exam Help
C Exam Help
Programming Exam Help
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked listAmit Vats
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
fathimahardwareelect
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
poblettesedanoree498
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
rohit219406
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
vishalateen
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
Himadri Sen Gupta
 
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
eyewaregallery
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
Masud Parvaze
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
RashidFaridChishti
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
BrianGHiNewmanv
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
fortmdu
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
ankit11134
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
JAGDEEPKUMAR23
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
MeghaKulkarni27
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
KylaMaeGarcia1
 

Similar to C Homework Help (20)

C Exam Help
C Exam Help C Exam Help
C Exam Help
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 

More from Programming Homework Help

C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
Programming Homework Help
 
Python Question - Python Assignment Help
Python Question - Python Assignment HelpPython Question - Python Assignment Help
Python Question - Python Assignment Help
Programming Homework Help
 
Best Algorithms Assignment Help
Best Algorithms Assignment Help Best Algorithms Assignment Help
Best Algorithms Assignment Help
Programming Homework Help
 
Design and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment HelpDesign and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment Help
Programming Homework Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
Programming Homework Help
 
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptxprogramminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
Programming Homework Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
Programming Homework Help
 
Algorithms Design Assignment Help
Algorithms Design Assignment HelpAlgorithms Design Assignment Help
Algorithms Design Assignment Help
Programming Homework Help
 
Algorithms Design Homework Help
Algorithms Design Homework HelpAlgorithms Design Homework Help
Algorithms Design Homework Help
Programming Homework Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
Programming Homework Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
Programming Homework Help
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
Programming Homework Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
Programming Homework Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
Programming Homework Help
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
Programming Homework Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
Programming Homework Help
 
Computer Science Assignment Help
Computer Science Assignment HelpComputer Science Assignment Help
Computer Science Assignment Help
Programming Homework Help
 
Software Construction Assignment Help
Software Construction Assignment HelpSoftware Construction Assignment Help
Software Construction Assignment Help
Programming Homework Help
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
Programming Homework Help
 
Programming Homework Help
Programming Homework Help Programming Homework Help
Programming Homework Help
Programming Homework Help
 

More from Programming Homework Help (20)

C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Python Question - Python Assignment Help
Python Question - Python Assignment HelpPython Question - Python Assignment Help
Python Question - Python Assignment Help
 
Best Algorithms Assignment Help
Best Algorithms Assignment Help Best Algorithms Assignment Help
Best Algorithms Assignment Help
 
Design and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment HelpDesign and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptxprogramminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Algorithms Design Assignment Help
Algorithms Design Assignment HelpAlgorithms Design Assignment Help
Algorithms Design Assignment Help
 
Algorithms Design Homework Help
Algorithms Design Homework HelpAlgorithms Design Homework Help
Algorithms Design Homework Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Computer Science Assignment Help
Computer Science Assignment HelpComputer Science Assignment Help
Computer Science Assignment Help
 
Software Construction Assignment Help
Software Construction Assignment HelpSoftware Construction Assignment Help
Software Construction Assignment Help
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Programming Homework Help
Programming Homework Help Programming Homework Help
Programming Homework Help
 

Recently uploaded

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
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
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
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
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
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
 
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
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
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
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 

Recently uploaded (20)

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
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
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
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
 
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
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
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
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 

C Homework Help

  • 1. For any help regarding C Homework Help visit : - https://www.programminghomeworkhelp.com/ , Email :- support@programminghomeworkhelp.com or call us at :- +1 678 648 4277 C Homework Help
  • 2. Linked List using C Homework Help The problems: PS3.0: Node and List Before you can work on the list operations, you'll need to create both a node and a list. The node should be responsible for node-y things, and the list for list-y things, in other words, they won't know much about each other. The list will accept a filled-in node and add it to the list. The node should be a struct, and it looks about the same as the one we've seen in lectures: typedef struct node { int value; node* next; } Here are the signatures for both node's and list's functions. Note that this is just the starting set of functions; each problem will require you to (possibly) add new functions to one or both of list and node. For nodes: programminghomeworkhelp.com
  • 3. node* createNode(int value); //Create a new node with a given value For lists: bool addNode(node* node); //Add a node to the list node* findNode(int value); //Find a node in the list bool deleteNode (node* node); //Delete a node in the list void printList(void); //Print the values in the list The returned boolean values should indicate success or failure of the operation. PS3.1 Add a set of nodes (in main.c) Create a singly linked list from this array: [89, 39, 18, 96, 71, 25, 2, 55, 60, -8, 9, 42, 69, 96, 24] Read each value in turn and call createNode, then addNode. Nodes must be dynamically allocated using malloc(). Print the list. programminghomeworkhelp.com
  • 4. PS3.2 Delete the largest nodes From main, ask the list to delete all of the nodes that contain the largest value in the list. The signature for this function will be similar to void deleteLargest(void); On the list side, deleteLargest should call an internal list function to find *all* nodes that contain the same largest value (there should be more than one), and then call the internal deleteNode function to delete all of the nodes found. Hint: You can use an array to collect the largest nodes as you find them. Print the list. PS3.3 Count the nodes in the list From main, ask the list to return the number of nodes in the list, and print the value. programminghomeworkhelp.com
  • 5. Solution: List: #include <stdio.h> PS3.4 Sort the list From main, ask the list to sort itself. Use a bubble-sort algorithm: •Starting from the top of the list, compare the value in the first node with the value in the second node •If the value in the second node is smaller, swap the two nodes, otherwise leave them in place •Move to the second node and compare its value with the third node, swapping them if necessary •Repeat this until you've reached the end of the list •Next, go back to the top and do it all over again •The list is sorted when you walk the entire list from top to bottom and do not perform any swaps The list should be sorted in-place. In other words, don't use a second list. Print the list programminghomeworkhelp.com
  • 6. #include <stdlib.h> #include "list.h" node *head = NULL; //Add a node to the list bool addNode(node *new_node) { if (head == NULL) { // This is add node to empty list. Just assign head to new node head = new_node; } else { // This is list with elment. Try to add new node to end of list node *current_node = head; while (current_node->next != NULL) { programminghomeworkhelp.com
  • 7. current_node = current_node->next; } // Now we are in end of list. Just add next to current node current_node->next = new_node; } return true; } //Find a node in the list node* findNode(int value) { node *current_node = head; while (current_node != NULL) { if (current_node->value == value) { // If this node contain value is the same. Just return it return current_node; } // Go the next node for next check current_node = current_node->next; } // Go to end of node. And we can not found anything. Just return null. return NULL; programminghomeworkhelp.com
  • 8. } //Delete a node in the list bool deleteNode(node *del_node) { if (head == NULL) { // Current list is empty. We can not delete any more return false; } else if (head->value == del_node->value) { // If this is delete the head node. node *tmp = head->next; free(head); head = tmp; return true; } else { // If this is delete the middle node node *current_node = head; node *prev_node = NULL; while (current_node != NULL) { if (current_node->value == del_node->value) programminghomeworkhelp.com
  • 9. { // Find the node to be delete. prev_node->next = current_node->next; free(current_node); return true; } // If this is not a node delete. Just move to next node for checking. prev_node = current_node; current_node = current_node- >next; } } // Can not found any node in list for remove. return false; } //Print the values in the list void printList(void) { node *current_node = head; while (current_node) { printf("%d ", current_node->value); current_node = current_node- >next; programminghomeworkhelp.com
  • 10. } printf("n"); } void deleteLargest(void) { // First step is find the largest node int largest_value = head->value; node *current_node = head->next; while (current_node) { if (current_node->value > largest_value) { // If found new node largest. Just keep track it. largest_value = current_node->value; } // Move to next node for check current_node = current_node->next; } // Now try to delete all node largest node. node *del_node = malloc(sizeof(node)); del_node->value = largest_value; programminghomeworkhelp.com
  • 11. del_node->next = NULL; // Loop until no more largest value in node. while (findNode(largest_value) != NULL) { deleteNode(del_node); } free(del_node); } int count(void) { int cnt = 0; node* current_node = head; while(current_node) { cnt++; current_node = current_node->next; } return cnt; } void sort(void) { if(head == NULL) { // Don't need to sort the empty list return; } else { programminghomeworkhelp.com
  • 12. if(compare_node->value < current_node->value) { // We need to swap 2 node int tmp_value = current_node->value; current_node->value = compare_node->value; compare_node->value = tmp_value; } compare_node = compare_node->next; } current_node = current_node->next; } } } Main: #include <stdio.h> #include <stdlib.h> #include "node.h" #include "list.h" int main(int argc, char** argv) { // PS3.1 - Add a set of nodes. node* current_node = head; node* compare_node = NULL; while(current_node) { compare_node = current_node->next; while(compare_node) { programminghomeworkhelp.com
  • 13. // Create a signly linked list from this array. [89, 39, 18, 96, 71, 25, 2, 55, 60, -8, 9, 42, 69, 96, 24] int array[15] = {89, 39, 18, 96, 71, 25, 2, 55, 60, -8, 9, 42, 69, 96, 24}; for(int i = 0; i < 15; i++) { node* new_node = createNode(array[i]); addNode(new_node); } // Print list printf("PS3.1 - List after add: "); printList(); printf("======================================== ===n"); // PS3.2 Delete the largest nodes printf("PS3.2 - Try to delete the largest node.n"); deleteLargest(); printf("List after delete: "); printList(); printf("======================================== ===n"); // PS3.3 - Count the nodes in the list printf("PS3.3 - Count the nodes in the listn"); int list_size = count(); printf("Count nodes in list: %dn", list_size); programminghomeworkhelp.com
  • 14. //Create a new node with a given value node* createNode(int value) { // Allocate a new node node *new_node = (node*) malloc(sizeof(node)); if (new_node) { // Check the allocated is successfull new_node->value = value; new_node->next = NULL; } return new_node; } // PS3.4 - Sort the list printf("PS3.4 - List after sort: "); sort(); printList(); // j o h n n y t u o t - g m a i l - c o m return 0; } Node: #include <stdio.h> #include <stdlib.h> #include "node.h" programminghomeworkhelp.com