0% found this document useful (0 votes)
10 views

hds

The document contains a C program that implements a singly linked list with functions to insert nodes, display the list, calculate its size, and check if it is a palindrome. The main function demonstrates these functionalities by creating a linked list, displaying it, and checking if it is a palindrome. The program outputs whether the linked list is a palindrome based on the inserted values.

Uploaded by

sanketgithub10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

hds

The document contains a C program that implements a singly linked list with functions to insert nodes, display the list, calculate its size, and check if it is a palindrome. The main function demonstrates these functionalities by creating a linked list, displaying it, and checking if it is a palindrome. The program outputs whether the linked list is a palindrome based on the inserted values.

Uploaded by

sanketgithub10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<stdio.

h>

#include<stdlib.h>

struct Node

int data;

struct Node *next;

};

void insertFirst (struct Node **start, int data)

struct Node *newNode = (struct Node *) malloc (sizeof (struct Node));

newNode->data = data;

newNode->next = *start;

*start = newNode;

void display (struct Node *node)

printf ("Linked List : \n");


while (node != NULL)

printf ("%d ", node->data);

node = node->next;

printf ("\n");

int size (struct Node *node)

int counter=0;

while (node != NULL)

node = node->next;

counter++;

return counter;

int checkPalindrome (struct Node *start, int counter)

int i = 0, j;

struct Node *front, *rear;

while (i != counter / 2)

{
front = rear = start;

for (j = 0; j < i; j++)

front = front->next;

for (j = 0; j < counter - (i + 1); j++)

rear = rear->next;

if (front->data != rear->data)

return 0;

else

i++;

return 1;

int main ()

struct Node *start = NULL;

int counter,result;

insertFirst (&start, 2);

insertFirst (&start, 3);


insertFirst (&start, 4);

insertFirst (&start, 3);

insertFirst (&start, 2);

display (start);

counter = size(start);

result = checkPalindrome (start, counter);

if (result == 1)

printf("The linked list is a palindrome.\n");

else

printf("The linked list is not a palindrome.\n");

}
return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy