geeksforgeeks
  • Courses
  • Tutorials
  • Practice
  • Jobs
  • DSA
  • Practice Problems
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Data Science
  • Machine Learning
  • Courses
  • Linux
  • DevOps
Videos
January 10, 2025 |44.1K Views

Pairwise swap elements of a given linked list

Linked List, linked-list
 Save  Share   Like
Description
Discussion

Given a singly linked list, write a function to swap elements pairwise.

Input : 1->2->3->4->5->6->NULL 
Output : 2->1->4->3->6->5->NULL


Start from the head node and traverse the list. While traversing swap data of each node with its next node’s data.


Pairwise swap elements of a given linked list : https://www.geeksforgeeks.org/pairwise-swap-elements-of-a-given-linked-list/

Recommendations
Video Thumbnail
08:48
Video Thumbnail
5.7K Views | 10/01/2025...
Identical Linked Lists
Video Thumbnail
16:14
Video Thumbnail
92.2K Views | 10/01/2025...
Merge two sorted linked lists
Video Thumbnail
06:44
Video Thumbnail
28.5K Views | 10/01/2025...
Remove duplicates from a sorted linked list
Video Thumbnail
02:37
Video Thumbnail
73.4K Views | 04/01/2025...
Circular Linked List | Set 1 (Introduction and Applications)
Video Thumbnail
20:50
Video Thumbnail
13.3K Views | 31/07/2024...
Reversing a linked list
Video Thumbnail
07:00
Video Thumbnail
36.4K Views | 31/07/2024...
Detect and Remove Loop in a Linked List (Explained in Hindi)
Video Thumbnail
07:00
Video Thumbnail
71.6K Views | 18/07/2024...
Detection of Loop in a Linked List (Explained In Hindi)
Video Thumbnail
11:07
Video Thumbnail
3.5K Views | 15/07/2024...
Sorted insert for circular linked list
Video Thumbnail
06:03
Video Thumbnail
13.1K Views | 15/07/2024...
Find the length of loop in linked list
Video Thumbnail
08:50
Video Thumbnail
11.0K Views | 15/07/2024...
Delete middle of linked list
GeeksforGeeks
location
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
location
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play StoreGFG App on App Store
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • Careers
  • Contact Us
  • Corporate Solution
  • Campus Training Program
  • Explore
  • POTD
  • Practice Problems
  • Connect
  • Blogs
  • Upskill Courses
  • Tutorials
  • Programming Languages
  • DSA
  • Web Technology
  • AI, ML & Data Science
  • DevOps
  • CS Core Subjects
  • GATE
  • School Subjects
  • Software and Tools
  • Courses
  • ML and Data Science
  • DSA and Placements
  • Web Development
  • Data Science
  • Programming Languages
  • DevOps & Cloud
  • GATE
  • MongoDB Certifications
  • Offline Centers
  • Noida
  • Bengaluru
  • Hyderabad
  • Kolkata
  • Preparation Corner
  • Interview Corner
  • Aptitude
  • Puzzles
  • GfG 160
  • System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved