循环链表

2025 年 1 月 12 日 | 2 分钟阅读

算法

在循环链表的任意位置添加节点

  • 步骤 1 开始
  • 步骤 2 存储要创建链表的数据。
  • 步骤 3 存储要在链表任意位置插入的元素。
  • 步骤 4 存储位置并启动计数器。
  • 步骤 5 检查 head 是否为 null,如果不是则继续执行步骤 6。
  • 步骤 6 将存储的数据存入指定位置。
  • 步骤 7 为存储的数据创建新链接,并将其指向下一个位置。
  • 步骤 8 更改新节点插入位置的下一个和上一个节点的链接地址。
  • 步骤 9 停止
DS Addition of node at any position of Circular linked list

程序

输出

Enter the data to create linked list:10                                                                                         
                                                                                                                                 
 If you wish to continue press 1 otherwise 0:1                                                                                   
                                                                                                                                 
 Enter the data:20                                                                                                               
                                                                                                                                 
 If you wish to continue press 1 otherwise 0:1                                                                                   
                                                                                                                                 
 Enter the data:30                                                                                                               
                                                                                                                                 
 If you wish to continue press 1 otherwise 0:1                                                                                   
                                                                                                                                 
 Enter the data:40                                                                                                               
                                                                                                                                 
 If you wish to continue press 1 otherwise 0:1                                                                                   
                                                                                                                                 
 Enter the data:50                                                                                                               
                                                                                                                                 
 If you wish to continue press 1 otherwise 0:0                                                                                   
                                                                                                                                 
 Enter the data for particular position:60                                                                                       
                                                                                                                                 
 Enter the position to be inserted:3                                                                                             
10->20->60->30->40->50       

下一主题在开头插入