Tuesday, August 31, 2010

Delete a linked list using recursion in C++

#include < iostream >
using namespace std;

struct Node{
    int num;
    Node* next;
};

//Here address of pointer to the list is passed so that head of the  list  will not be a local variable.

void DeleteListRecursion(Node*& list){
    if(list == NULL)
        return;
    else
     DeleteListRecursion(list->next);
     delete(list);
     list = NULL;
}



Node* Insert(int number, Node* list){
    Node* node = new Node;
    node->num = number;
    node->next = list;
    return node;
}

//TEST

int main(){
       
    Node* list = NULL;

    list = Insert(5,list);
    list = Insert(7,list);
    list = Insert(9,list);
    list = Insert(4,list);
    list = Insert(6,list);
    list = Insert(3,list);
   
    DeleteListRecursion(list);

    return 0;
}

Saturday, August 28, 2010

Data Structures You Should Know

  • UnSorted List Using Arrays
  • UnSorted List Using Linked List
  • Sorted List Using Arrays
  • Sorted List Using Linked List
  • Doubly Linked List
  • Circular List
  • Stack Using Arrays
  • Stack Using LinkedList
  • Queue Using arrays
  • Queue Using LinkedList
  • Recursion Problems
  • Binary Tree
  • Sorting
    • Bubble Sort           Code          Example
    • Selection Sort        Code          Example
    • Insertion Sort         Code          Example
    • QuickSort              Code          Example
    • MergeSort             Code          Example
    • HeapSort             Code          Example
    • Radix Sort             Code          Example
    • Hashing