943,661 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 7168
  • C++ RSS
Aug 13th, 2006
0

radix sort using queue and linked list

Expand Post »
i wan to know the code for the radix sort using a queue and a radix sort using a linked list
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
happy8899 is offline Offline
24 posts
since Aug 2006
Aug 13th, 2006
0

Re: radix sort using queue and linked list

Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Aug 13th, 2006
0

Re: radix sort using queue and linked list

Where are you stuck?
Reputation Points: 197
Solved Threads: 12
Junior Poster
Grunt is offline Offline
147 posts
since Jul 2006
Aug 21st, 2006
0

Re: radix sort using queue and linked list

Quote 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
happy8899 is offline Offline
24 posts
since Aug 2006
Aug 21st, 2006
0

Re: radix sort using queue and linked list

Quote 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.
Reputation Points: 197
Solved Threads: 12
Junior Poster
Grunt is offline Offline
147 posts
since Jul 2006
Aug 21st, 2006
0

Re: radix sort using queue and linked list

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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Aug 23rd, 2006
0

Re: radix sort using queue and linked list

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
C++ Syntax (Toggle Plain Text)
  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

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
happy8899 is offline Offline
24 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: quick ? about vector naming conventions
Next Thread in C++ Forum Timeline: if then statement





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC