Tags » Linked List

Check whether a linked list is palindrome or not

Implementation in C

 #include < stdio.h >
 #include < stdbool.h >
 #include < malloc.h >

struct node
   char data;
   struct node *next;

bool Check_Palindrome(struct node **left, struct node *right)
   bool leftRightData;

   if(right == NULL) //base condition
      return true;
    /*check if sublist is palindrome or not-if not then no need to check left,
     right data */
      return false;
   //compare left data with right data
   leftRightData = ((*left)->data == right->data);
   *left = (*left)->next; // move left to next node of linked list

   return leftRightData;

void push(struct node **head, char ch)
   struct node *temp = (struct node*)malloc(sizeof(struct node));
   temp->data = ch;
   temp->next = (*head);
   (*head) = temp;
int main()
   struct node* head = NULL;
   char str[] = "level"; // suppose the palindrome be level
   int index;
   for(index = 0; str != '\0'; index++) //string into linked list
   push(&head, str);
   Check_Palindrome(&head, head) ? 382 more words
Linked List

Concept: Linked List

Linked list (Theory):

  1. It is a collection of nodes of elements in sequential order.
  2. Dynamic representation.
  3. As per requirement, we can allocate or de-allocate the memory space.
  4. 240 more words
All Posts

Delete last occurrence of a key from Singly Linear Linked List

Given a linked list and a key to be deleted. Delete last occurrence of key from the list. The list may have duplicates.


Input:   1->2->3->5->2->10, key = 2
Output:  1->2->3->5->10 223 more words
All Posts

Add 1 to a number represented as singly linear linked list

Number is represented in linked list such that each digit corresponds to a node in linked list. Add 1 to it. For example 1999 is represented as (1-> 9-> 9 -> 9) and adding 1 to it should change it to (2->0->0->0) … 187 more words

All Posts

Linear vs Non Linear Data Structures

Data structure is a way to organize a data in computer so that it can be used efficiently.

In computer science, Data Structure is classified into two categories : 412 more words

Data Structure

Given a list, rotate the list to the right by k places, where k is non-negative.

For example:
Given 1->2->3->4->5->NULL and k = 2, 12 more words

Two Points