Answer to Question #227413 in C for Tony

Question #227413
Implement a doubly circular SORTED linked list (using dummy node) that consists of following operations:
a. Insert (into the sorted position)
b. Show all
c. Search(search for a specific integer data)
d. Delete (find it and delete)
e. Length (current length of the list)
1
Expert's answer
2021-08-19T03:22:16-0400
using namespace std;
#include <omp.h>
#include <stdio.h>


struct Node 
{
   int data;
   struct Node *next;
};
struct Node* head = NULL;


void InsertData(int NewtData)
{
	struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
	new_node->data = NewtData;
	new_node->next = head;
	head = new_node;
}


void DisplayLinkedList(void) 
{
   	struct Node* ptr; ptr=head;
  	while (ptr != NULL) 
   	{
    	cout<< ptr->data <<" ";
    	ptr = ptr->next;
   	}
}


void DeleteNode(struct node **head, int k)
{
      struct node *temp;
      if(*head->data == k)
      {
          temp = *head;    
          *head = (*head)->next;
          free(temp);
      }
}


int SearchLinkedList(int dat) 
{
   	int Flag=0;
	struct Node* ptr; ptr=head;
  	while (ptr != NULL) 
   	{
   		if(ptr->data == dat) 
   		{
		 	cout<< ptr->data <<" ";
		 	Flag=1;
    	}
		ptr = ptr->next;
   	}
   	return(Flag);
}


void max(void)
{
   	struct Node* ptr; ptr=head;
   	int Max;
	Max = ptr->data;
  	while (ptr != NULL) 
   	{
    	if(ptr->data >= Max) Max = ptr->data;
    	ptr = ptr->next;
   	}
   	cout<<"\nMaximum Element = "<<Max;
}






int main() 
{
	int List[5] = {1, 3, 5, 33, 22};
    int n;
    for(n=0;n<5;n++) InsertData(List[n]);
    
    cout<<"\nThe linked list- is: ";
    DisplayLinkedList();
    max();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS