Single Linked List – Insert, Delete and Print

#include <stdio.h>
#include <stdlib.h>

typedef struct Node {
int sd;
struct Node *next;
}node;

void insere(node ** head, int sd){
node ** ptr2=head;
if(*ptr2==NULL){
(*ptr2)=(node*)malloc(sizeof(node));
(*ptr2)->sd=sd;
(*ptr2)->next=NULL;
}else{
while(*ptr2 != NULL){
ptr2 = &(*ptr2)->next;
}
(*ptr2)=(node*)malloc(sizeof(node));
(*ptr2)->sd=sd;
(*ptr2)->next=NULL;
}
}

void remove(node ** head,int sd){
node ** ptr2;
for(ptr2= head; *ptr2 != NULL; ptr2 = &(*ptr2)->next)
{
if((*ptr2)->sd == sd)
{
*ptr2 = (*ptr2)->next;
break;
}
}
}

void printLista (node * head) {
printf(“Lista: “);
node * ptr =head;
while(ptr!=NULL){
printf(“%d “, ptr->sd);
ptr=ptr->next;
}
printf(“\n”);
}

About these ads

Tags:

4 Responses to “Single Linked List – Insert, Delete and Print”

  1. lakshya Says:

    give a search

  2. lakshya Says:

    give a search opition

  3. Domozhirov Says:

    Eta ochyn chorosho!!! DOMOZHIROV!!!

  4. ankit Says:

    also include audio attach to it so that one can understand in a better way..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: