4/22/2018

DCT2023 DS & FP. Lab Linked Lists. (#2)

1. Write a program in C++ to insert a new node at the beginning of a Singly Linked List.
Test Data :
Input the number of nodes : 3
Input data for node 1 : 5
Input data for node 2 : 6
Input data for node 3 : 7
 

Expected Output :
 Data entered in the list :                                                                                  
 Data = 5                                                                                                    
 Data = 6                                                                                                    
 Data = 7 


Solution (you may use your own solution)









































2. Write a program in C++ to create a singly linked list of n nodes and count the number of nodes. 
Test Data :
Input the number of nodes : 3
Input data for node 1 : 5
Input data for node 2 : 6
Input data for node 3 : 7
Expected Output :
 Data entered in the list are :                                                                              
 Data = 5                                                                                                    
 Data = 6                                                                                                    
 Data = 7                                                                                                    
                                                                                                             
 Total number of nodes = 3  


3. Write a program in C++ to insert a new node at the end of a Singly Linked List.
Test Data and Expected Output :

Input the number of nodes : 3                                                                                
 Input data for node 1 : 5                                                                                    
 Input data for node 2 : 6                                                                                    
 Input data for node 3 : 7                                                                                    
                                                                                                              
 Data entered in the list are :                                                                               
 Data = 5                                                                                                     
 Data = 6                                                                                                     
 Data = 7                                                                                                     
                                                                                                              
 Input data to insert at the end of the list : 8                                                              
                                                                                                              
 Data, after inserted in the list are :                                                                       
 Data = 5                                                                                                     
 Data = 6                                                                                                     
 Data = 7 
 Data = 8 
 
4. Write a program in C++ to insert a new node at the middle of Singly Linked List. 

Test Data and Expected Output : 
Input the number of nodes (3 or more) : 4                                                                    
 Input data for node 1 : 1                                                                                    
 Input data for node 2 : 2                                                                                    
 Input data for node 3 : 3                                                                                    
 Input data for node 4 : 4                                                                                    
                                                                                                              
 Data entered in the list are :                                                                               
 Data = 1                                                                                                     
 Data = 2                                                                                                     
 Data = 3                                                                                                     
 Data = 4                                                                                                     
                                                                                                              
 Input data to insert in the middle of the list : 5                                                           
 Input the position to insert new node : 3                                                                    
                                                                                                              
 Insertion completed successfully.                                                                             
                                                                                                              
 The new list are :                                                                                           
 Data = 1                                                                                                     
 Data = 2                                                                                                     
 Data = 5                                                                                                     
 Data = 3                                                                                                     
 Data = 4 
 
5. Write a program in C++ to delete first node of Singly Linked List. 

Test Data : 

Input the number of nodes : 3 

Input data for node 1 : 2 

Input data for node 2 : 3 

Input data for node 3 : 4 

Expected Output : 
 Data entered in the list are :                                                                               
 Data = 2                                                                                                     
 Data = 3                                                                                                     
 Data = 4                                                                                                     
                                                                                                              
 Data of node 1 which is being deleted is :  2                                                                
                                                                                                              
 Data, after deletion of first node :                                                                         
 Data = 3                                                                                                     
 Data = 4 
 
6. Write a program in C++ to delete a node from the middle of Singly Linked List. 

Test Data and Expected Output : 
Input the number of nodes : 3                                                                                
 Input data for node 1 : 2                                                                                    
 Input data for node 2 : 5                                                                                    
 Input data for node 3 : 8                                                                                    
                                                                                                              
 Data entered in the list are :                                                                               
 Data = 2                                                                                                     
 Data = 5                                                                                                     
 Data = 8                                                                                                     
                                                                                                              
 Input the position of node to delete : 2                                                                     
                                                                                                              
 Deletion completed successfully.                                                                             
                                                                                                              
 The new list are  :                                                                                          
 Data = 2                                                                                                     
 Data = 8 
 
7. Write a program in C++ to delete the last node of Singly Linked List. 

Test Data : 

Input the number of nodes : 3 

Input data for node 1 : 1 

Input data for node 2 : 2 

Input data for node 3 : 3

Expected Output : 
 Data entered in the list are :                                                                               
 Data = 1                                                                                                     
 Data = 2                                                                                                     
 Data = 3                                                                                                     
                                                                                                              
 The new list after deletion the last node are  :                                                             
 Data = 1                                                                                                     
 Data = 2 
 
8. Write a program in C++ to search an existing element in a singly linked list. 
Test Data and Expected Output : 
Input the number of nodes : 3                                                                                
                                                                                                              
 Input data for node 1 : 2                                                                                    
 Input data for node 2 : 5                                                                                    
 Input data for node 3 : 8                                                                                    
                                                                                                              
 Data entered in the list are :                                                                               
 Data = 2                                                                                                     
 Data = 5                                                                                                     
 Data = 8                                                                                                     
                                                                                                              
 Input the element to be searched : 5                                                                         
 Element found at node 2 
 

No comments:

Cara download Installer windows 10 dalam format ISO

1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan.  ...