Programme in c to create a single linked list, Data Structure & Algorithms

Q. Write  down a   programme  in  C  to  create  a  single  linked  list also  write the functions to do the following operations

(i)  To insert a new node at the end

(ii) To delete the first node                                                                                                                                     

Ans:

//Create a single list

struct node

{

int data;

struct node *link

}

struct node *p,*q;

//Inserting a node at the end(append)

append(struct node **q,int num)

{

struct node *temp; temp=*q; if(*q==NULL)

{

*q=malloc(sizeof(struct node *));

temp=*q;

}

else

{

while(temp        link!=NULL)

temp=temp   link;

temp   link = malloc(sizeof(struct node *));

temp=temp   link;

}

Temp   data=num;

temp     link=NULL;

}

//Delete the first node delete(struct node *q,int num)

{

struct node *temp;

temp=*q;

*q=temp   link;

free(temp);

}

Posted Date: 7/10/2012 7:08:48 AM | Location : United States







Related Discussions:- Programme in c to create a single linked list, Assignment Help, Ask Question on Programme in c to create a single linked list, Get Answer, Expert's Help, Programme in c to create a single linked list Discussions

Write discussion on Programme in c to create a single linked list
Your posts are moderated
Related Questions
Q. Create a heap with the given list of keys: 8, 20, 9, 4, 15, 10, 7, 22, 3, 12                                                  Ans: Creation

Program gives the program segment by using arrays for the insertion of an element to a queue into the multiqueue. Program: Program segment for the insertion of any element to t

create aset of ten numbers.then you must divide it into two sets numbers which are set of odd numbers and set of even numbers.

The smallest element of an array's index is called its Lower bound.

CMY Model  The cyan, magenta, yellow (CMY) colour model is a subtractive model based on the colour absorption properties of paints and inks. As such it has become the standard

What is Solid modeling Solid modeling is the most powerful of the 3-D modeling technique. It provides the user with complete information about the model. Defining an object wit

calculate gpa using an algorithm

Q. Write an algorithm that counts number of nodes in a linked list.                                       A n s . Algo rithm to Count No. of Nodes in Linked List C

This algorithm inputs 3 numbers, every number goes through successive division by 10 until its value is less than 1. An output is produced which comprise the number input and a val

Asymptotic notation Let us describe a few functions in terms of above asymptotic notation. Example: f(n) = 3n 3 + 2n 2 + 4n + 3 = 3n 3 + 2n 2 + O (n), as 4n + 3 is of