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
1. Use the Weierstrass condition, find the (Strongly) minimizing curve and the value of J min for the cases where x(1) = 0, x(2) = 3. 2. The system = x 1 + 2u; where

Ans: I nsertion into the B-tree: 1.  First search is made for the place where the new record must be positioned. As soon as the keys are inserted, they are sorted into th

What are the properties of an algorithsm?

A graph with n vertices will absolutely have a parallel edge or self loop if the total number of edges is greater than n-1

Q. Explain the Hash Tables, Hash function and Hashing Techniques properly?             A n s . H as h Table is explained as follows : A hash table is a data struc

Let a be a well-formed formula. Let c be the number of binary logical operators in a. (Recall that ?, ?, ?, and ? are the binary logical operators). Let s be the number of proposit

two standards ways of traversing a graph in data structure

In the book the following methods are presented: static void selectionSort(Comparable[] list) static void insertionSort(Comparable[] list) static boolean linearSearch(Comparable

Question 1 Describe the following- Well known Sorting Algorithms Divide and Conquer Techniques Question 2 Describe in your own words the different asymptotic func

Given the following search tree, state the order in which the nodes will be searched for breadth first, depth first, hill climbing and best first search, until a solution is reache