radix sort using queue and linked list

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 20
Reputation: happy8899 is an unknown quantity at this point 
Solved Threads: 0
happy8899 happy8899 is offline Offline
Newbie Poster

radix sort using queue and linked list

 
0
  #1
Aug 13th, 2006
i wan to know the code for the radix sort using a queue and a radix sort using a linked list
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: radix sort using queue and linked list

 
0
  #2
Aug 13th, 2006
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: radix sort using queue and linked list

 
0
  #3
Aug 13th, 2006
Where are you stuck?
The key to eliminating bugs from your code is learning from your mistakes.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 20
Reputation: happy8899 is an unknown quantity at this point 
Solved Threads: 0
happy8899 happy8899 is offline Offline
Newbie Poster

Re: radix sort using queue and linked list

 
0
  #4
Aug 21st, 2006
Originally Posted by Grunt
Where are you stuck?
i dunno how to develope a program that need to use linked list both the single linked list and double linked list which need to enter the list of number using linked list and using radix sort that is developed using linked list
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: radix sort using queue and linked list

 
0
  #5
Aug 21st, 2006
Originally Posted by happy8899
i dunno how to develope a program that need to use linked list both the single linked list and double linked list which need to enter the list of number using linked list and using radix sort that is developed using linked list
Buddy we can't explain everything to you here. For that you have to look into the books. If you have a specific doubt, post here. Definetly someone here will help you out.
The key to eliminating bugs from your code is learning from your mistakes.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: radix sort using queue and linked list

 
0
  #6
Aug 21st, 2006
Well can you do the "populate a linked list with some data" part of the problem?

There's no point talking about the "sort" side of things until you can do that.

I mean, "here is my linked list code", how do I radix sort it would at least show some effort on your part.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 20
Reputation: happy8899 is an unknown quantity at this point 
Solved Threads: 0
happy8899 happy8899 is offline Offline
Newbie Poster

Re: radix sort using queue and linked list

 
0
  #7
Aug 23rd, 2006
quote=Salem;245110]Well can you do the "populate a linked list with some data" part of the problem?

There's no point talking about the "sort" side of things until you can do that.

I mean, "here is my linked list code", how do I radix sort it would at least show some effort on your part.[/quote]

first linked list
  1. # include <iostream>
  2. using namespace std;
  3. #ifndef DLL_QUEUE
  4. #define DLL_QUEUE
  5. #include <list>
  6. template <class T>
  7. class linkedList
  8. {
  9. public:
  10. linkedList()
  11. {
  12. }
  13. void clear()
  14. {
  15. lst.clear();
  16. }
  17. bool empty() const
  18. {
  19. return lst.empty();
  20. }
  21. T& front()
  22. {
  23. return lst.front();
  24. }
  25. T dequeue()
  26. {
  27. T el = lst.front();
  28. lst.pop_front();
  29. return el;
  30. }
  31. void enqueue(const T& el)
  32. {
  33. lst.push_back(el);
  34. }
  35. private:
  36. list<T> lst;
  37. };
  38. #endif

  1. # ifndef INT_LINKED_LIST
  2. # define INT_LINKED_LIST
  3. using namespace std;
  4. class IntSLLNode
  5. {
  6. public:
  7. int info;
  8. IntSLLNode *next;
  9. IntSLLNode (int el, IntSLLNode *ptr = 0)
  10. {
  11. info = el;
  12. next =ptr;
  13. }
  14. };
  15. class IntSLList
  16. {
  17. public:
  18. IntSLList()
  19. {
  20. head = tail = 0;
  21. }
  22. ~IntSLList();
  23.  
  24. int empty()
  25. {
  26. return head ==0;
  27. }
  28.  
  29. void addToHead(int);
  30. void addToTail(int);
  31. int deleteFromHead();
  32. int deleteFromTail();
  33. void deleteNode(int);
  34. bool isInList(int) const;
  35. void insertNode(int&);
  36. void print();
  37. int get();
  38.  
  39. private:
  40. IntSLLNode *head, *tail;
  41. int t;
  42. };
  43. IntSLList::~IntSLList()
  44. {
  45. for(IntSLLNode *p; !empty();)
  46. {
  47. p = head->next;
  48. delete head;
  49. head = p;
  50. }
  51. }
  52. void IntSLList::addToHead(int el)
  53. {
  54. head = new IntSLLNode(el, head);
  55. if(tail == 0)
  56. tail == head;
  57. }
  58.  
  59. void IntSLList::addToTail(int el)
  60. {
  61. if(tail!= 0)
  62. {
  63. tail->next = new IntSLLNode(el);
  64. tail = tail->next;
  65. }
  66.  
  67. else head = tail = new IntSLLNode(el);
  68. }
  69. void IntSLList::deleteNode(int el)
  70. {
  71. if(head!=0)
  72. if(head == tail && el == head->info)
  73. {
  74. delete head;
  75. head = tail =0;
  76. }
  77. else if (el == head->info)
  78. {
  79. IntSLLNode *temp = head;
  80. head = head->next;
  81. delete temp;
  82. }
  83. else
  84. {
  85. IntSLLNode *pred, *tmp;
  86. for (pred = head, tmp = head->next; tmp!=0 && !(tmp->info == el);
  87. pred = pred->next, tmp = tmp->next);
  88. if (tmp!=0)
  89. {
  90. pred->next = tmp->next;
  91. if(tmp == tail)
  92. tail = pred;
  93. delete tmp;
  94. }
  95. }
  96. }
  97. int IntSLList::deleteFromHead()
  98. {
  99. int el = head->info;
  100. IntSLLNode *tmp = head;
  101. if(head == tail)
  102. head = tail = 0;
  103. else head = head->next;
  104. //cout<<" "<<head->info;
  105. delete tmp;
  106. return el;
  107. }
  108.  
  109. int IntSLList::deleteFromTail()
  110. {
  111. int el = tail->info;
  112. if (head == tail)
  113. {
  114. delete head;
  115. head = tail = 0;
  116. }
  117. else
  118. {
  119. IntSLLNode *tmp;
  120. for (tmp = head; tmp->next !=tail; tmp = tmp->next)
  121. delete tail;
  122. tail = tmp;
  123. tail->next=0;
  124. }
  125. return el;
  126. }
  127. void IntSLList::print()
  128. {
  129. IntSLLNode *current;
  130.  
  131. current = head;
  132.  
  133. while (current != NULL)
  134. {
  135. cout<< current->info<<" ";
  136. current = current->next;
  137. }
  138. }
  139. int IntSLList::get()
  140. {
  141. IntSLLNode *current;
  142. IntSLLNode *yy;
  143.  
  144. current = head;
  145. yy = current;
  146.  
  147. cout<<"get";
  148. t = yy->info;
  149. cout<<endl<<t<<" ggggg "<<endl;
  150. yy = yy->next;
  151. cout<<yy->info;
  152. //current->next = NULL;
  153. //head = head->next;
  154. //delete current;
  155. return t;
  156. }
  157. #endif

here is my linked list how to use it in radix sort to sort a list
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 5368 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC