• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Single Link List code using C Language

April 3, 2011 by ProjectsGeek Leave a Comment

Perform the Implementation of Single Link List

 

Source Code for Single Link list in C and C++ Language with the following functions ::

  • Create Single Link list
  • Display Single Link list
  • Insert Node
  • Delete node
  • Reverse Single Link list
  • Revert

Single link list Assignment is implemented using pointers with every function is divided modular to increase codes readability .

Single Link List C Language code

 

#include
#include

typedef struct node

{

int info;

struct node *lnk;

}node;

node* create();

node* alloc();

void display(node *);

node* insert(node *,int);

node* insert1(node *,int);

node* dlt(node *,int);

node* reverse(node *);

void main()

{

int ch,n,a[10],key,ch1;

node *f,*f1,*f2;

do

{

clrscr();

printf("\t\t\tLINKED LIST MAIN MENU\n");

printf("\t\t\t1:CREATE\n");

printf("\t\t\t2:DISPLAY\n");

printf("\t\t\t3:INSERT\n");

printf("\t\t\t4:DELETE\n");

printf("\t\t\t5:REVERSE\n");

printf("\t\t\t6:REVERT\n");

printf("\t\t\t7:EXIT\n");

printf("\t\tENTER YOUR CHOICE\n");

scanf("%d",&ch);

switch(ch)

{

case 1:clrscr();

f=create();

getch();

break;

case 2:clrscr();

printf("\n\t\tDISPLAYING THE LINKED LIST\n\n");

display(f);

getch();

break;

case 3:clrscr();

do

{

clrscr();

printf("\n\t\tINSERT MENU");

printf("\n\t\t1.BEFORE A NO\n\t\t2.AFTER A NO\n\t\t3.EXIT");

scanf("%d",&ch1);

switch(ch1)

{

case 1: clrscr();

printf("ENTER THE ELEMENT OF THE LIST");

scanf("%d",&key);

f=insert(f,key);

display(f);

getch();

break;

case 2: clrscr();

printf("ENTER THE ELEMENT OF THE LIST");

scanf("%d",&key);

f1=insert1(f,key);

display(f1);

getch();

break;

case 3:

break;

}

}while(ch1!=3);

break;

case 4: clrscr();

printf("ENTER THE ELEMENT OF THE LIST");

scanf("%d",&key);

f1=dlt(f,key);

display(f1);

getch();

break;

case 5: f2=reverse(f);

display(f2);

f2=reverse(f2);

getch();

break;

case 6: f=reverse(f);

display(f);

printf("\n\t\tLIST REVERSED\t\t");

getch();

break;

case 7:

break;

default:

printf("WRONG CHOICE !!!! RE ENTER");

getch();

break;

}

}while(ch!=7);

}

node* create()

{

node *f,*nw,*lst;

f=NULL;

do

{

nw=alloc();

if(f==NULL)

f=nw;

else

lst->lnk=nw;

lst=nw;

printf("\n\n\tDO YOU WANT TO ENTER ANOTHER DATABASE(y/n)?");

}while(getche()=='y');

return f;

}

node* alloc()

{

node *f;

f=(node *)malloc(sizeof(node));

f->lnk=NULL;

printf("\n\tENTER THE ELEMENT TO BE ADDED");

scanf("%d",&f->info);

return f;

}

void display(node *f)

{

if(f==NULL)

{

printf("\n\n\t\tLIST NOT PRESENT !!!!");

return;

}

printf("\n\tINFO\tRPTR\tADD\n");

while(f!=NULL)

{

printf("\t%d\t%d\t%d\n",f->info,f->lnk,f);

f=f->lnk;

}

}

node* insert(node *f,int key)

{

node *nw,*t;

if(f->info==key)

{

nw=alloc();

nw->lnk=f;

f=nw;

return f;

}

while(f->lnk!=NULL)

{

if(f->lnk->info==key)

{

nw=alloc();

nw->lnk=f->lnk;

f->lnk=nw;

return f;

}

f=f->lnk;

}

printf("\n\t\t\tELEMENT NOT FOUND !!!!");

return f;

}

node* insert1(node *f,int key)

{

node *nw,*p;

f=p;

while(p!=NULL)

{

if(key==p->info)

{

nw=alloc();

nw->lnk=p->lnk;

p->lnk=nw;

return f;

}

p=p->lnk;

}

printf("element not found");

}

node* dlt(node *f,int key)

{

node *p,*q;

p=f;

if(f==NULL)

{

printf("\n\tLINKED LIST EMPTY");

return f;

}

if(key==f->info)

{

f=f->lnk;

free(p);

return f;

}

else

{

while(p->lnk!=NULL)

{

if(key==(p->lnk)->info)

{

q=p->lnk;

p->lnk=p->lnk->lnk;

free(q);

}

p=p->lnk;

}

return f;

}

printf("ELEMENT NOT FOUND");

}

node* reverse(node *f)

{

node *p,*t,*r;

p=NULL;

t=f;

r=t->lnk;

while(t!=NULL)

{

t->lnk=p;

p=t;

t=r;

if(t!=NULL)

r=r->lnk;

}

return(p);

}

Download Source Code

Other Projects to Try:

  1. Double Link List code using C Langauge
  2. Circular Link List using C Language
  3. Hash table code in C Language
  4. Sparse Matrix Operations Code using C Langauge
  5. BFS AND DFS Algorithm using C Language

Filed Under: Fundamentals of Datastructure Tagged With: Datastructure Assignments

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy