hello sir i'm a new user,i just want to ask if you have sample programs which deals on linked list....if possible not the add.edit,delete program

Recommended Answers

All 2 Replies

You can't do a linked list without the add, edit, and delete functions. But do a search for linked lists and you'll get hundreds of hits, such as this list here at DaniWeb

hello sir i'm a new user,i just want to ask if you have sample programs which deals on linked list....if possible not the add.edit,delete program

Here is a simple one. I can't write without classes, anyway.

#include <iostream>

struct listelem {
  char data;//any type here
  listelem* next;
};

class list {
private:
   listelem *h; 
public:
   list() { h=0; }//0 means empty list
   ~list() { release(); }
   void prepend(char c);//add to the start of the list
   void del() { listelem*temp=h;
                     h = h -> next;
                     delete temp; }
   listelem* first() {return h; }
   void print();
   void release();
};

void list::prepend(char c)
{
   listelem *temp = new listelem;
   
   temp -> next = h;
   temp -> data = c; h = temp;
   h = temp;
}

void list::print() {
  listelem *temp = h;

  while(temp != 0) {
      cout<<temp -> data << " -> ";
      temp = temp->next;
  }
  cout<<"\n###\n";
}

void list::release()
{
   while(h!=0)
       del();
}

If you want, I can post difficult one with templates.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.