Question

Assume we have a linked list with 12 nodes pointed to by FIRST. Write a function...

Assume we have a linked list with 12 nodes pointed to by FIRST.

Write a function that deletes the first node.

Write a function that deletes the 7th node.

Write a function that deletes the last node.

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

a)

#include<stdio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *link;
};
struct node *FIRST;
void createlist()
{
char ch;
printf("Enter n for break:\n");
scanf("%c",&ch);
while(ch!='n')
{
struct node *NEW_NODE,*SAVE;int x;
NEW_NODE=(struct node *)malloc(sizeof(struct node));
printf("Enter Data:");
scanf("%d",&x);
NEW_NODE->info=x;
if(FIRST==NULL)
{
NEW_NODE->link=NULL;
FIRST=NEW_NODE;
}
else
{
SAVE=FIRST;
while(SAVE->link!=NULL)
{
SAVE=SAVE->link;
}
SAVE->link=NEW_NODE;
NEW_NODE->link=NULL;
}
fflush(stdin);
printf("Enter n for break:\n");
scanf("%c",&ch);
}
}
void delfirst()
{
struct node *SAVE;
if (FIRST==NULL)
printf("Linked List is Empty");
else if(FIRST->link==NULL)
{
printf("Deleted element is %d",FIRST->info);
FIRST=NULL;
}
else
{
printf("Deleted element is %d",FIRST->info);
FIRST=FIRST->link;
}

}
void display()
{
struct node *SAVE;
if(FIRST==NULL)
{
printf("sll is empty\n");
return;
}
printf("elements are:\n");
SAVE=FIRST;
while(SAVE!=NULL)
{
if(SAVE->link==NULL)
printf("|%d|",SAVE->info);
else
printf("|%d|->",SAVE->info);
SAVE=SAVE->link;
}
printf("\n");
return;
}
void main()
{
FIRST=NULL;
createlist();
display();
delfirst();
display();
}

Add a comment
Know the answer?
Add Answer to:
Assume we have a linked list with 12 nodes pointed to by FIRST. Write a function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function to implement linked list consisting of five nodes. Store the data in the...

    Write a function to implement linked list consisting of five nodes. Store the data in the nodes in the order given below. Also, write a function to display the data stored in the implemented linked list. in C++ programming George, Paul, Ross, Joe, Elaine, Robert1 Insert three nodes in between second node and third node in the linked list that you implemented in problem 1. Store the following data in the new (inserted) nodes in the following order. (You have...

  • Q2 [15 pts] Linked list: For this question use class Node.java Assume this file implements a...

    Q2 [15 pts] Linked list: For this question use class Node.java Assume this file implements a node in a linked list. It has the following public data members: ➢ int data ➢ Node next Write class Node and Class single linked list then write the following functions: 2.2 Remove duplicates from an unsorted linked list Write a Java method removeDuplicates() which takes a list and deletes any duplicate nodes from the list. The list is not sorted. Example: if the...

  • 2) (10 pts) Write a function that takes in a pointer to a linked list of...

    2) (10 pts) Write a function that takes in a pointer to a linked list of nodes storing integers and a variable named value, and returns the number of nodes in the list storing that value. For example, if a list pointed to by listPtr stores 2, 6, 2, 3, 4, 2, 6, and 6 and value = 6, your function should return 3, since 6 appears in the list 3 times. Please use the struct and function prototype provided...

  • A linked list is constructed of nodes described by the following structure: struct node{ char data;...

    A linked list is constructed of nodes described by the following structure: struct node{ char data; struct node *next; }; Assume a linked list containing a sentinel node is constructed from the above nodes. Write a function named "count"-prototyped as int count(struct node*sent)- that accepts a pointer to the sentinel node; counts the number of data (non-sentinel) nodes containing the character 'A'; and returns that count as the function value.

  • Linked Lists: Suppose you have a doubly linked list with both head and tail pointers, that...

    Linked Lists: Suppose you have a doubly linked list with both head and tail pointers, that stores integers. Implement a non-recursive function that takes a linked list, searches for an integer, and removes the node with the first occurrence of that integer and also removes the node directly after it regardless of value . This function will return to address of the resulting list. You ca n assume that there will be at least three nodes, and if there is...

  • java singly linked list write a routine, which will travel through the list second and third...

    java singly linked list write a routine, which will travel through the list second and third list by taking every 2nd node from the first list and 3rd node Given a pointer to creating from the first list and putting them into the two newly created lists. (For example: If the original list had 12 nodes it should remain with nodes 1, 4, 7, and 10. The 2nd list would be made up of nodes 2, 5, 8, and 11...

  • use python In class, we've studied Singly-Linked Lists which are made of nodes that point at...

    use python In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...

  • use python In class, we've studied Singly-Linked Lists which are made of nodes that point at...

    use python In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...

  • use python In class, we've studied Singly-Linked Lists which are made of nodes that point at...

    use python In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...

  • Write a Python function to implement the quick sort algorithm over a singly linked list. The...

    Write a Python function to implement the quick sort algorithm over a singly linked list. The input of your function should be a reference pointing to the first node of a linked list, and the output of your function should also be a reference to the first node of a linked list, in which the data have been sorted into the ascending order. (You may use the LinkedQueue class we introduced in the lecture directly in your program.)

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